views:

1170

answers:

5

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

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


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

+1  A: 

UTC is indepent from Daylight Saving Time, while GMT does "move" with DST. And your date is in the summer, so....

Philippe Leybaert
-1 according to wikipedia (see comment above http://stackoverflow.com/posts/2292350/edit)
kenny
See my comment on nobugz answer. "GMT Standard Time" moves with DST, "Greenwich Mean Time" doesn't (like UTC).
frankadelic
GMT stands for Greenwich Mean Time.
kenny
kenny - I am speaking in the context of .NET's TimeZoneInfo class. If you execute TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time") and TimeZoneInfo.FindSystemTimeZoneById("Greenwich Mean Time"), you will find that the two objects have different behavior with respect to DST.
frankadelic
A: 

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

Hope this helps some.

Chris
GMT (Greenwich Mean Time) is largely misused these days and for the cases of international or global standards, it should be normally replaced with UTC, except for dealing with "standard time" within the UK.
mctylr
+3  A: 

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

Asad Butt
+1  A: 

GMT does not adjust for daylight savings time. 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.

Hans Passant
Interesting... whereas TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time") returns false, same as UTC.
frankadelic
I don't think Windows is messing up, it's just a terminology confusion. They're using GMT to refer to the timezone containing Dublin, Edinburgh, Lisbon, London among others, and those **do** use daylight savings.
Mark Ransom
I don't disagree.
Hans Passant
I don't disagree as well! GMT (as pointed out by Asad) means Greenwich Mean Time - which is precisely defined as solar time as measured at the prime meridian. By including this name in a timezone is just stupid.
Chris F
A: 

[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 confue 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!

Chris F