UTC和GMT标准时间在.NET之间的差异 [英] Difference between UTC and GMT Standard Time in .NET

查看:442
本文介绍了UTC和GMT标准时间在.NET之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.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 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\GMT Standard Time. You'd better stick with UTC.

这篇关于UTC和GMT标准时间在.NET之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆