简体   繁体   English

.NET 中 UTC 和 GMT 标准时间的区别

[英]Difference between UTC and GMT Standard Time in .NET

In .NET, the following statements return different values:在 .NET 中,以下语句返回不同的值:

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

..and this... ..和这个...

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

Why is this?为什么是这样? I thought UTC and GMT Standard Time are equivalent.我认为 UTC 和 GMT 标准时间是等效的。


Update更新

Upon further testing, I find that the following appear to be equivalent:经过进一步测试,我发现以下内容似乎是等效的:

"UTC" “世界标准时间”

"Greenwich Mean Time" “格林威治标准时间”

"Morocco Standard Time" 《摩洛哥标准时间》

Whereas, the following is different during summer months:而在夏季,以下情况有所不同:

"GMT Standard Time" “格林威治标准时间”

Perhaps my question should be, why are "Greenwich Mean Time" and "GMT Standard Time" different?也许我的问题应该是,为什么“格林威治标准时间”和“格林威治标准时间”不同?

End Update结束更新

GMT does not adjust for Daylight saving time (DST). GMT调整为夏令时(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.这不是 .NET 问题,而是 Windows 搞砸了。 The registry key that TimeZoneInfo uses is HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\GMT Standard Time. TimeZoneInfo 使用的注册表项是 HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones\\GMT 标准时间。 You'd better stick with UTC.你最好坚持使用UTC。

[I am really just backing up Hans Passant's answer] [我真的只是在支持 Hans Passant 的回答]

There seems to me to be a confusion over the use of the term "GMT" which seems to be used to mean "Greenwich Mean Time" and also the timezone used in the UK/Ireland - which flips between GMT in winter and British Summer time in summer and doesn't seem to have a well defined name in its own right!在我看来,对术语“GMT”的使用感到困惑,该术语似乎用于表示“格林威治标准时间”以及英国/爱尔兰使用的时区 - 在冬季的格林威治标准时间和英国夏令时间之间转换在夏天,它本身似乎没有一个明确的名字!

To confuse things even more, I ran the sample code from the MSDN docs for TimeZoneInfo.GetSystemTimeZones and looked at the output.为了让事情更加混乱,我运行了MSDN 文档中 TimeZoneInfo.GetSystemTimeZones的示例代码并查看了输出。

I was very surprised to see the following definition of the "GMT Standard Time" timezone我很惊讶地看到以下“GMT 标准时间”时区的定义

ID: GMT Standard Time
   Display Name:  (UTC) Dublin, Edinburgh, Lisbon, London
   Standard Name:                       GMT Standard Time
   Daylight Name:                       GMT Daylight Time   ***Has Daylight Saving Time***
   Offset from UTC:                       0 hours, 0 minutes
   Number of adjustment rules:                          1
   Adjustment Rules:
      From 01/01/0001 00:00:00 to 31/12/9999 00:00:00
      Delta: 01:00:00
      Begins at 01:00 on Sunday of week 5 of March
      Ends at 02:00 on Sunday of week 5 of October

It seems (at least to me) that whoever was in charge of defining timezones in Microsoft has really muddied the waters even further here.似乎(至少对我而言)负责在 Microsoft 中定义时区的人在这里真的把水弄得更混乱了。

They obviously wanted to describe the timezone in use in UK/Ireland but they gave it an ID that included the terms "GMT" and UTC in the ID and the display name.他们显然想描述在英国/爱尔兰使用的时区,但他们给了它一个 ID,在 ID 和显示名称中包含术语“GMT”和 UTC。 I feel fairly confident that this timezone definition (whatever it should be called) is not UTC.我相当确信这个时区定义(无论它应该叫什么)不是UTC。 It may have times that are very similar to UTC for half of the year but that is all!它可能有半年与 UTC 非常相似的时间,但仅此而已!

This is a late response that the original questioner is unlikely to read but which people who google for this topic may find.这是一个迟到的回复,原始提问者不太可能阅读,但谷歌搜索此主题的人可能会找到。

The names GMT Standard Time and GMT Daylight Time are unknown outside of Redmond. GMT 标准时间GMT 夏令时的名称在雷德蒙德以外是未知的。 They are mythical animals that appear only in the bestiary called the Windows Registry.它们是只出现在名为 Windows 注册表的动物寓言中的神话动物。 In the real world, in winter the UK observes GMT (Greenwich Mean Time) and in summer it observes BST (British Summer Time).在现实世界中,英国在冬天遵守 GMT(格林威治标准时间),在夏天遵守 BST(英国夏令时)。 BST is 1 hour ahead (eastwards) of GMT. BST 比 GMT 提前 1 小时(向东)。 Europeans generally do not talk about "daylight time" but "summer time", at least in the languages I know.欧洲人一般不谈论“夏令时”而是“夏令时”,至少在我知道的语言中是这样。

One respondent has said one should use UTC in preference to GMT .一位受访者表示应该优先使用UTC而不是GMT This advice, from the International Astronomical Union, dates back to 1935. Its point was that, before 1925, GMT was counted from noon not midnight, so even though it was 10 years later, the possibility of ambiguity might still have then persisted.这个来自国际天文学联合会的建议可以追溯到 1935 年。它的要点是,在 1925 年之前,格林威治标准时间是从中午而不是午夜开始计算的,所以即使是 10 年后,歧义的可能性仍然存在。 But it's a bit out of date now.但是现在有点过时了。 For the past 80 years the terms GMT and Universal Time have been almost synonymous.在过去的 80 年里,GMT 和世界时这两个术语几乎是同义词。 Not quite, of course.当然不完全是。 But you need an astronomer to explain the difference to you.但是您需要一位天文学家来向您解释其中的区别。 If you are concerned about hours, not seconds, you probably won't care.如果您关心小时,而不是秒,您可能不会在意。

GMT is about civil timekeeping in English-speaking countries. GMT 是关于英语国家的民用计时。 It is not obsolete.它并没有过时。 It is enshrined in law in the UK, Ireland, Canada, even Belgium.它被载入英国、爱尔兰、加拿大甚至比利时的法律。

The various flavours of Universal Time are about astronomical timekeeping.世界时间的各种风格都是关于天文计时的。

And civil timekeeping, I think, was what the original question was about.我认为,民用计时就是最初的问题。

The difference is as follows:区别如下:

  • Greenwich Mean Time (GMT) is a term originally referring to mean solar time at the Royal Observatory in Greenwich, London.格林威治标准时间 (GMT)是一个术语,最初指的是伦敦格林威治皇家天文台的平均太阳时。 whereas然而
  • Coordinated Universal Time (UTC) (French: Temps Universel Coordonné) is a time standard based on International Atomic Time (TAI) with leap seconds added at irregular intervals to compensate for the Earth's slowing rotation 协调世界时 (UTC) (法语:Temps Universel Coordonné)是一种基于国际原子时 (TAI) 的时间标准,并以不规则的间隔添加闰秒以补偿地球的缓慢自转
  • Day Light Saving Time (DST) on the other hand is advancing clocks To and for with season changes, To make max use of day light.另一方面,夏令时 (DST)是随着季节变化而推进时钟,以最大限度地利用日光。

    "It is observed in many countries but not all" . "It is observed in many countries but not all" It might be variable, as last summer some countries like Pakistan, decided to bring back clocks a month later than they normally do.这可能是可变的,因为去年夏天,巴基斯坦等一些国家决定比平时晚一个月恢复时钟。

  • World Time Zones is a good resource for up-to date time information around the globe. World Time Zones是获取全球最新时间信息的好资源。

Hope this helps希望这可以帮助

"GMT Standard Time " = UK Time (which will be GMT+0 in the winter or GMT+1 if it's the summer in the UK.) “GMT标准时间” = 英国时间(如果是英国的夏季,则冬季为 GMT+0 或 GMT+1。)

Basically if you want to convert UTC to UK time, use "GMT Standard Time "基本上,如果您想将 UTC 转换为英国时间,请使用“GMT标准时间

Plain old "GMT" (or Greenwich Mean Time) is more or less UTC, give or take a few milliseconds.普通的旧“GMT”(或格林威治标准时间)或多或少是 UTC,给出或花费几毫秒。 It doesn't adjust for daylight saving in the UK so we've never had a use case for it.它不会针对英国的夏令时进行调整,因此我们从未有过使用案例。

This has kind of been explained in a very long winded way by all the other answers, some of which are misleading or contradictory, hence I wanted to provide yet another answer in the hope it saves someone all the reading and confusion.所有其他答案都以非常冗长的方式解释了这一点,其中一些答案具有误导性或矛盾性,因此我想提供另一个答案,希望它可以避免某些人的阅读和困惑。

The TimeZoneInfo object having the .Id of "GMT Standard Time" corresponds to the .DisplayName of "(UTC) Dublin, Edinburgh, Lisbon, London" .具有"GMT Standard Time".IdTimeZoneInfo对象对应于"(UTC) Dublin, Edinburgh, Lisbon, London".DisplayName

This time zone uses Greenwich Mean Time (GMT) (UTC+0) during the winter months, and British Summer Time (BST) (UTC+1) during the summer months.该时区在冬季使用格林威治标准时间 (GMT) (UTC+0),在夏季使用英国夏令时间 (BST) (UTC+1)。

Reference here .参考这里

The time zone for UTC has an .Id of "UTC" and a .DisplayName of "(UTC) Coordinated Universal Time" . UTC 时区的.Id"UTC".DisplayName"(UTC) Coordinated Universal Time"

They are two different time zone settings.它们是两种不同的时区设置。

Also, when looking at the list of time zone display names in Windows:此外,在查看 Windows 中的时区显示名称列表时:

时区列表

The value in parenthesis is just the standard offset, so while it looks like there are four different settings for UTC, there is really only one.括号中的值只是标准偏移量,因此虽然看起来 UTC 有四种不同的设置,但实际上只有一种。 It's just that the other three zones use UTC as their base offset when Daylight Saving Time is not in effect.只是其他三个区域在夏令时不生效时使用 UTC 作为它们的基本偏移量。

Here is a discussion of Coordinated Univeral Timezones .这里是Coordinated Universal Timezones的讨论。 It seems that UTC is usually used when a high precision is need for the time frame.当时间范围需要高精度时,似乎通常使用UTC。 Greenwhich Meantime is pretty close and is used back and forth with UTC. Greenwhich 同时非常接近并且与 UTC 来回使用。

Hope this helps some.希望这对一些人有所帮助。

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

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