Tuesday, October 9, 2012

WinRT: No FindSystemTimeZoneId available.

The TimeZoneInfo class in the regular .NET Framework has the FindSystemTimeZoneId method. It allows you to specify a TimeZone id and return the related time zone information.
// Get Brussels Standard Time zone 
TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time"); 
A list of Time Zone id’s can be found here: http://www.xiirus.net/articles/article-_net-convert-datetime-from-one-timezone-to-another-7e44y.aspx.

However if you try to execute this code in WinRT, you’ll notice that the FindSystemTimeZoneById method is not available.

The reason could be found in the same MSDN documentation:
“FindSystemTimeZoneById tries to match id to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry under Windows XP and Windows Vista. This branch does not necessarily contain a comprehensive list of time zone identifiers.”
I’m assuming that this registry key is not available from WinRT. So anyone who knows an alternative way to get this information?

The only solution I can think of is doing a call to the server and calculate the TimeZoneInfo there…


Dan Rigby said...

There are native Win32 APIs available that WinRT apps can access that will let you get a lot of this information (http://msdn.microsoft.com/en-us/library/windows/desktop/hh706893). Take a look at chapter 16 of "Programming Windows, 6th Edition" by Charles Petzold.

Bart Wullems said...

Thanks for the tip! We'll try this...

Anonymous said...

Well, if you're using magic strings like "Romance Standard Time" anyway...

try this:
System.TimeZoneInfo.FromSerializedString("Romance Standard Time;60;(UTC+01:00) Brussels, Copenhagen, Madrid, Paris;Romance Standard Time;Romance Daylight Time;[01:01:0001;12:31:9999;60;[0;02:00:00;3;5;0;];[0;03:00:00;10;5;0;];];");

Oren Novotny said...


Just came across this post. If you still need it, I wrapped up the Win32 api and made it available to WinRT and WP8 apps. There's a single API that works across all current platforms: