We are saving all dates in UTC in our database and also saving offset for each user.
We are converting to localtime by following function:
Private Function ConvertToLocalDateTime(ByVal utcOffset As Integer?, ByVal DateToConvert As DateTime?) As DateTime?
getdatetime = DateToConvert.Value.AddHours(utcOffset)
If getdatetime.IsDaylightSavingTime Then
getdatetime.AddHours(-1)
End If
Return getdatetime
End Function
But still dates are 1 or 2 hours off.
How can we convert correctly to localtime from utcoffset also taking care of daylight saving?
只要将DateToConvert
的Kind
属性正确设置为Utc
,您就可以调用DateToConvert.ToLocalTime()
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.