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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2292334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 13:56:37  来源:igfitidea点击:

Difference between UTC and GMT Standard Time in .NET

.nettimezoneutcgmt

提问by frankadelic

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 appearto 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

结束更新

采纳答案by Hans Passant

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

GMT并没有调整夏令时(DST)。你可以在这个网站上从马的嘴里听到它

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.

这不是 .NET 问题,而是 Windows 搞砸了。TimeZoneInfo 使用的注册表项是 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\GMT 标准时间。你最好坚持使用UTC。

回答by Chris Fewtrell

[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.GetSystemTimeZonesand 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. I feel fairly confident that this timezone definition (whatever it should be called) is notUTC. It may have times that are very similar to UTC for half of the year but that is all!

他们显然想描述在英国/爱尔兰使用的时区,但他们给了它一个 ID,在 ID 和显示名称中包含术语“GMT”和 UTC。我相当确信这个时区定义(无论它应该叫什么)不是UTC。它可能有半年与 UTC 非常相似的时间,但仅此而已!

回答by BoarGules

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 Timeand GMT Daylight Timeare unknown outside of Redmond. They are mythical animals that appear only in the bestiary called the Windows Registry. In the real world, in winter the UK observes GMT (Greenwich Mean Time) and in summer it observes BST (British Summer Time). BST is 1 hour ahead (eastwards) of GMT. Europeans generally do not talk about "daylight time" but "summer time", at least in the languages I know.

GMT 标准时间GMT 夏令时的名称在雷德蒙德以外是未知的。它们是只出现在名为 Windows 注册表的动物寓言中的神话动物。在现实世界中,英国在冬天遵守 GMT(格林威治标准时间),在夏天遵守 BST(英国夏令时)。BST 比 GMT 提前 1 小时(向东)。欧洲人一般不谈论“夏令时”而是“夏令时”,至少在我知道的语言中是这样。

One respondent has said one should use UTCin preference to 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. But it's a bit out of date now. For the past 80 years the terms GMT and Universal Time have been almost synonymous. 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.

一位受访者表示应该优先使用UTC而不是GMT。这个来自国际天文学联合会的建议可以追溯到 1935 年。它的要点是,在 1925 年之前,格林威治标准时间是从中午而不是午夜开始计算的,所以即使是 10 年后,歧义的可能性仍然存在。但是现在有点过时了。在过去的 80 年里,GMT 和世界时这两个术语几乎是同义词。当然不完全是。但是您需要一位天文学家来向您解释其中的区别。如果您关心小时,而不是秒,您可能不会在意。

GMT is about civil timekeeping in English-speaking countries. It is not obsolete. It is enshrined in law in the UK, Ireland, Canada, even Belgium.

GMT 是关于英语国家的民用计时。它并没有过时。它被载入英国、爱尔兰、加拿大甚至比利时的法律。

The various flavours of Universal Time are about astronomical timekeeping.

世界时间的各种风格都是关于天文计时的。

And civil timekeeping, I think, was what the original question was about.

我认为,民用计时就是最初的问题。

回答by Asad

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. 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
  • 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.

    "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 Zonesis a good resource for up-to date time information around the globe.

  • 格林威治标准时间 (GMT)是一个术语,最初指的是伦敦格林威治皇家天文台的平均太阳时。然而
  • 协调世界时 (UTC)(法语:Temps Universel Coordonné)是一种基于国际原子时 (TAI) 的时间标准,并以不规则的间隔添加闰秒以补偿地球自转放缓
  • 另一方面,夏令时 (DST)是随着季节变化而推进时钟,以最大限度地利用日光。

    "It is observed in many countries but not all". 这可能是可变的,因为去年夏天,巴基斯坦等一些国家决定比平时晚一个月恢复时钟。

  • World Time Zones是获取全球最新时间信息的好资源。

Hope this helps

希望这可以帮助

回答by Matt Johnson-Pint

The TimeZoneInfoobject having the .Idof "GMT Standard Time"corresponds to the .DisplayNameof "(UTC) Dublin, Edinburgh, Lisbon, London".

TimeZoneInfo具有.Idof的对象"GMT Standard Time"对应于.DisplayNameof "(UTC) Dublin, Edinburgh, Lisbon, London"

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 .Idof "UTC"and a .DisplayNameof "(UTC) Coordinated Universal Time".

UTC 的时区有一个.Idof"UTC"和一个.DisplayNameof "(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 中的时区显示名称列表时:

Time Zone List

时区列表

The value in parenthesis is just the standardoffset, so while it looks like there are four different settings for UTC, there is really only one. It's just that the other three zones use UTC as their base offset when Daylight Saving Time is not in effect.

括号中的值只是标准偏移量,因此虽然看起来 UTC 有四种不同的设置,但实际上只有一种。只是其他三个区域在夏令时不生效时使用 UTC 作为它们的基本偏移量。

回答by Chris

Here is a discussion of Coordinated Univeral Timezones. It seems that UTC is usually used when a high precision is need for the time frame. Greenwhich Meantime is pretty close and is used back and forth with UTC.

这里是Coordinated Universal Timezones的讨论。当时间范围需要高精度时,似乎通常使用UTC。Greenwhich 同时非常接近并且与 UTC 来回使用。

Hope this helps some.

希望这对一些人有所帮助。