UTC和GMT标准时间在.NET之间的差异差异、时间、标准、UTC

2023-09-02 10:26:29 作者:fantastic 异想天开

在.NET中,下列语句返回不同的值:

In .NET, the following statements return different values:

Response.Write(
  TimeZoneInfo.ConvertTime(
    DateTime.Parse("2010-07-01 5:30:00.000"),
    TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"),
    TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time"))
  );
// displays 7/1/2010 1:30:00 PM

..这...

Response.Write(
  TimeZoneInfo.ConvertTime(
    DateTime.Parse("2010-07-01 5:30:00.000"),
    TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"),
    TimeZoneInfo.FindSystemTimeZoneById("UTC"))
  );
// displays 7/1/2010 12:30:00 PM

这是为什么?我想UTC和GMT标准时间是相等的。

Why is this? I thought UTC and GMT Standard Time are equivalent.

更新

经过进一步的测试,我发现下面的显示的是等同的:

Upon further testing, I find that the following appear to be equivalent:

UTC

格林威治标准时间

摩洛哥标准时间

然而,在夏季,以下是不同的:

Whereas, the following is different during summer months:

GMT标准时间

也许我的问题应该是,为什么是格林威治时间和GMT标准时间有什么不同?

Perhaps my question should be, why are "Greenwich Mean Time" and "GMT Standard Time" different?

末更新

推荐答案

北京时间确实的没有的调整日光节省时间(DST)。您可以从马的嘴在这个网站上听到它。

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

添加此行的code看到了问题的根源:

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

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

输出:真

这是不是.NET的问题,是Windows搞乱。是的TimeZoneInfo使用注册表项为HKLM SOFTWARE 微软的Windows NT CURRENTVERSION Time区域格林尼治标准​​时间。你最好与UTC坚持。

This is not a .NET problem, it is Windows messing up. The registry key that TimeZoneInfo uses is HKLMSOFTWAREMicrosoftWindows NTCurrentVersionTime ZonesGMT Standard Time. You'd better stick with UTC.