8

In the year 2013, the United Kingdom won't start daylight savings time until March 31st.

Still, TimeZoneInfo.ConvertTimeToUtc subtracts one hour when I try to convert a given time to UTC time.

Why is this? Do I need to tell this method that daylight savings time is not active?

var now = new DateTime(DateTime.Now.Ticks, DateTimeKind.Unspecified);
var convertedTime = TimeZoneInfo.ConvertTimeToUtc(now, TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard time"));
Console.WriteLine(convertedTime); // subtracts one hour, even though England time and GMT should be equal
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Jim G.
  • 15,141
  • 22
  • 103
  • 166

3 Answers3

8

You are simply using the wrong time zone. England is in the "GMT Standard Time" zone.

The "W. Europe Standard Time" zone is for continental Europe, Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna, UTC+01:00.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Are you sure about that? This website says, "The UK is in the Western European Time Zone." http://wwp.greenwichmeantime.com/time-zone/europe/uk/ – Jim G. Mar 17 '13 at 03:01
  • Here's another one which says exactly what I'm saying: WET = GMT, but when DST is in effect, WET = GMT + 1. http://wwp.greenwichmeantime.co.uk/time-zone/europe/uk/time/ – Jim G. Mar 17 '13 at 03:11
  • 7
    Yes, I'm sure. You'll need to use Windows timezone names, not whatever some web page calls it. – Hans Passant Mar 17 '13 at 03:15
  • @HansPassant: [Wikipedia also claims](http://en.wikipedia.org/wiki/Western_European_Time) WET = UTC, but .NET gives a value of UTC+1 for WET. – Dan W Feb 23 '15 at 22:14
3

[NOTE: This answer assumes the computer running the code is in the GMT timezone]

It's because "W. Europe Standard time" isn't the same timezone as UTC according to .Net (even though it should be). This is very odd, and seems like a bug in the .Net libraries.

Due to this, you've inadvertently told it to convert a time to UTC and passed it a UTC (i.e. GMT time) but then told it that the time is in "W. Europe Standard time", which is an hour ahead of UTC.

So naturally, the resulting time in an hour different.

Step by step:

var now = new DateTime(DateTime.Now.Ticks, DateTimeKind.Unspecified);

This sets now to the time in UTC.

var convertedTime = TimeZoneInfo.ConvertTimeToUtc(now, TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard time")

This converts now to UTC, assuming that now is in "W. Europe Standard time", i.e. UTC+1. But it isn't! Therefore the result is incorrect.

[EDIT in response to comments below]

Note that "W. Europe Standard time" should be UTC, but it isn't for some reason. And when you do this:

TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard time")

it returns UTC+1 rather than the (apparently) correct UTC. It even changes the name to "W. Europe Daylight Time". Seems like it might be a curious bug?

[Second Edit]

Check out the Microsoft Time Zone Index Values (and also here). (Note Neither of those links are actually for Windows 7, but they contain the same definitions.)

It has an entry for "W. Europe Standard Time" which definitely states (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
  • If you look at any of the online converters, and you try to convert a UK time to UTC, you'll see that they're the same and that they will be until March 31st. Am I missing something? – Jim G. Mar 17 '13 at 00:36
  • Are you in the UK? If you are, your code will cause the time to be out by an hour. – Matthew Watson Mar 17 '13 at 00:37
  • 1
    “It's because "W. Europe Standard time" isn't the same timezone as UTC.” Really? Do you have a reference for that? Because [Wikipedia disagrees with you](http://en.wikipedia.org/wiki/Western_European_Time). – svick Mar 17 '13 at 00:45
  • @svick: Yep. I agree with you. – Jim G. Mar 17 '13 at 00:48
  • @svick But my registry says the [opposite](http://i.imgur.com/v0SK5KX.png). _Weird_.. – Soner Gönül Mar 17 '13 at 00:51
  • @SonerGonul: Interesting. That might have something to do with the bug. – Jim G. Mar 17 '13 at 00:56
  • Do this: `var timezone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard time")` and then look at it under the debugger. `timezone.BaseUtcOffset` has the value `01:00:00`. Whether this is right or wrong is a different matter of course, but this is where the difference is coming from. Also note that the name "magically" has changed to "W. Europe Daylight Time" - which isn't what was passed in! So the looks suspiciously like some kind of library bug. – Matthew Watson Mar 17 '13 at 01:03
  • @MatthewWatson Aren't you looking at `DaylightName` property? Because I don't see what you're suggesting. – svick Mar 17 '13 at 01:09
  • @MatthewWatson I looked at `timezone.BaseUtcOffset` on the debugger and I see `00:00:00`. Somethings really weird.. I suspiciously kind of bug also.. – Soner Gönül Mar 17 '13 at 01:09
  • 2
    So it seems that Windows “W. Europe Standard time” is not the same as “Western European Time”. That's really confusing. – svick Mar 17 '13 at 01:10
  • 2
    @svick Yeah, on Windows registry `W. Europe Standard Time` matches with `Western European Summer Time` on [wikipedia](http://en.wikipedia.org/wiki/Western_European_Summer_Time) not with `Western European Time` – Soner Gönül Mar 17 '13 at 01:14
  • This statement is a bit misguided `It's because "W. Europe Standard time" isn't the same timezone as UTC` because UTC is NOT a timezone. UTC is a time standard. – onefootswill Dec 15 '21 at 23:46
-1

Well the two we have are western european time, and western european summer/daylight time isnt it? It might be that by entering Western European standard time, you're automatically matching to the closest, which would be summer or daylight - regardless of whether standard is listed as a timezone.

Incidentally, British summer time is the same as Western European daylight/summer time. And Greenwich meantime matches Western European time - same timezone, but BST started historically earlier, before matching with the EU rules in 2002. Effectively, same system different name.