Jimmyt1988 Jimmyt1988 - 3 months ago 16
C# Question

UTC converted to Central Europe Standard Time is 2 hours in front not 1

I'm trying to understand why my date is wrong:

DateTime databaseUtcTime = new DateTime(2016, 8, 15, 10, 20, 0, DateTimeKind.Utc);
var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");
var testDateTime = TimeZoneInfo.ConvertTimeFromUtc(databaseUtcTime, timeZone);


testDateTime
outputs 15/08/2016 12:20:00 rather than 15/08/2016 11:20:00
why is this?
Shouldn't it be 1 hour forward from UTC, not 2 ?

EDIT----

Thanks Jon Skeet,

If this helps anyone, i resorted to using:

if(testDateTime.IsDaylightSavingTime())
{
testDateTime = testDateTime.AddHours(-1);
}


Albeit you not knowing the context, this could be helpful to know how to get rid of daylight saving time when running certain explicit testing on time.

Answer

The time zone with an ID of "Central Europe Standard Time" is just the one used by central Europe... it doesn't really mean standard time.

As central Europe is observing daylight savings at the moment, the offset really is UTC+2.

It's very unfortunate that the IDs used in Windows time zones are misleading like this... but the TimeZoneInfo implementation itself is correct.

(This isn't all that's wrong with Windows time zone names... see Matt Johnson's post on the matter for more...)