TimeZoneInfo bug in .net 4.5


I have recently updated my os with .net 4.5 framework and compiled all my applications using it. unfortunately some of the automatic tests i wrote now fails on the Assert constructions concerning DateTime types.

After a deep analysis i turned out this:

in .net 4.0

DateTime dateUsing40 = new DateTime(2011, 4, 7); // ticks 634377312000000000    
dateUsing40.ToUniversalTime(); //ticks **634377240000000000

bool isDaylightST = dateUsing40.IsDaylightSavingTime(); // returns **true

in .net 4.5

DateTime dateUsing45 = new DateTime(2011, 4, 7); // ticks 634377312000000000
dateUsing45.ToUniversalTime(); //ticks  **634377276000000000    
bool isDaylightST = dateUsing45.IsDaylightSavingTime(); // returns **false

the System.Threading.Thread.CurrentThread.CurrentCulture is in both cases {it-IT}

Actually the date i used is in the range of the (italian but also for all countries that use WET) daylight time so it looks like there is a (huge) bug in the framework. however i didn't find anything useful about.

I verified in both machines:

  • regional settings are still set in Italian.
  • "Automatically adjust clock for daylight saving changes" is checked.
  • opening Regional and settings-> on tab Location -> current location is still Italy.
  • os Windows 7 x64


the framework update changed the DynamicDaylightTimeDisabled's value to 1. To solve this issue it's necessary to turn it to 0 and rebooting. Another way to do it is using the clock UI form.

Jeppe Stig Nielsen

Check the value of var tziLocal = TimeZoneInfo.Local; (cf. Shaun's answer), and its Id property.

Equivalently (I think), go to PowerShell and write:

Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Control\TimeZoneInformation -Name TimeZoneKeyName

and check the value of TimeZoneKeyName winreg "property". Get-ItemProperty can be shortened to just gp.

Based on experimentation, the CurrentCulture, CurrentUICulture and RegionInfo.CurrentRegion are not used, for determining "local time".

Instead if you go to Windows, Control Panel → Clock, Language, and Region → Date and Time → tab Date and Time → section Time zone → button Change time zone..., changing that zone seems to work.

Of course, if Windows registry contains wrong settings for Italy, typically the ID "W. Europe Standard Time" (not "Romance Standard Time", not "Central European Standard Time"), on your particular machine, that would be a problem.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment


Related Related