Difference between UTC and GMT Standard Time in .NET

后端 未结 7 1019
臣服心动
臣服心动 2020-11-27 04:45

In .NET, the following statements return different values:

Response.Write(
  TimeZoneInfo.ConvertTime(
    DateTime.Parse("2010-07-01 5:30:00.000"),         


        
7条回答
  •  误落风尘
    2020-11-27 05:22

    GMT does not adjust for Daylight saving time (DST). You can hear it from the horse's mouth on this web site.

    Add this line of code to see the source of the problem:

      Console.WriteLine(TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time").SupportsDaylightSavingTime);
    

    Output: True.

    This is not a .NET problem, it is Windows messing up. The registry key that TimeZoneInfo uses is HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\GMT Standard Time. You'd better stick with UTC.

提交回复
热议问题