时区对旧日期不正确

时间:2018-01-29 09:35:40

标签: .net vb.net datetime

我正在使用以下代码确定特定日期时间是GMT还是GMT + 1,具体取决于夏令时(英国夏令时)。

Private Function getFormattedDate(ByVal inDate As DateTime) As Object
    Dim sDate As String = inDate.ToString("s")

    sDate = sDate.Replace("T", " ")

    Dim zone As TimeZone = TimeZone.CurrentTimeZone
    Dim offset As TimeSpan = zone.GetUtcOffset(inDate)

    sDate &= " GMT+" & offset.TotalHours.ToString.PadLeft(2, "0"c) & ":00"

    Return sDate

End Function

这似乎运作良好并返回结果,例如:

2018年1月29日=“2018-01-29 09:23:54 GMT + 00:00”

2018-Mar-2018 =“2018-03-26 09:23:54 GMT + 01:00” - 三月最后一个星期天之后

但是,如果我使用1993年10月26日的日期,则会返回以下内容:

1993年10月26日=“1993-10-26 09:23:54 GMT + 01:00”

这是不正确的 - 正如我们所知,在1972年至1995年期间,BST在10月的第四个星期日格林威治标准时间02:00结束 - 这是第24天。任何人都可以看到我在这里使用的代码或我对英国夏令时的理解存在问题吗?

0 个答案:

没有答案