简体   繁体   English

UTC到夏令时

[英]UTC to locatime with daylight saving

We are saving all dates in UTC in our database and also saving offset for each user. 我们将所有日期保存在数据库的UTC中,并且还为每个用户保存了偏移量。

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. 但日期仍会减少1或2个小时。

How can we convert correctly to localtime from utcoffset also taking care of daylight saving? 我们如何在兼顾夏令时的情况下如何从utcoffset正确转换为本地时间?

只要将DateToConvertKind属性正确设置为Utc ,您就可以调用DateToConvert.ToLocalTime()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM