Difference between UTC and GMT Standard Time in .NET

后端 未结 7 930
臣服心动
臣服心动 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.

    0 讨论(0)
  • 2020-11-27 05:22

    [I am really just backing up Hans Passant's answer]

    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!

    To confuse things even more, I ran the sample code from the MSDN docs for TimeZoneInfo.GetSystemTimeZones and looked at the output.

    I was very surprised to see the following definition of the "GMT Standard Time" timezone

    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.

    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 not UTC. It may have times that are very similar to UTC for half of the year but that is all!

    0 讨论(0)
  • 2020-11-27 05:28

    The TimeZoneInfo object having the .Id of "GMT Standard Time" corresponds to the .DisplayName of "(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.

    Reference here.

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

    They are two different time zone settings.

    Also, when looking at the list of time zone display names in Windows:

    Time Zone List

    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. It's just that the other three zones use UTC as their base offset when Daylight Saving Time is not in effect.

    0 讨论(0)
  • 2020-11-27 05:31

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

    Hope this helps

    0 讨论(0)
  • 2020-11-27 05:40

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

    One respondent has said one should use UTC in 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.

    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.

    The various flavours of Universal Time are about astronomical timekeeping.

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

    0 讨论(0)
  • 2020-11-27 05:42

    "GMT Standard Time" = UK Time (which will be GMT+0 in the winter or GMT+1 if it's the summer in the UK.)

    Basically if you want to convert UTC to UK time, use "GMT Standard Time"

    Plain old "GMT" (or Greenwich Mean Time) is more or less UTC, give or take a few milliseconds. 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.

    0 讨论(0)
提交回复
热议问题