As I'm sure you know, the TimeZone support in the .NET Framework is abysmal to say the best. You can get the current time zone and also convert DateTime objects to UTC and that's pretty much it. Even with .NET Framework 3.5, Microsoft only fixed the problem on the desktop (by including the TimeZoneInfo class). The .NET Compact Framework still has no native TimeZone support. Here is an attempt to fix that.
I'm offering my TimeZoneInformation class free of charge for anyone that wants it.
The basis for this class is taken from here. William Stacy wrote this class for Windows. What it does is read the time zone information from the registry and then use regular (non .NET) functions to convert between them.
There is another version of this class found here. This one is written by Mike Dimmick.
I'm not sure who wrote it first, so I'm giving credit to both of them. Thanks guys!
There needed to be a bunch of changes made to that class in order for it to work on Windows Mobile.
First of all, the functions are located in a different DLL file in Windows Mobile than they do on Windows.
Also, there are no functions to convert to a generic time zone in Windows Mobile, only between local time zone and UTC. Due to this, my class has to set the local time zone to whatever time zone that you need for a split second to do the conversion. I hope that this will not cause any problems with 3rd party programs.
The biggest problem in Windows Mobile, however, is that time zone information is not stored anywhere in the registry. In fact, I have absolutely no idea where it is stored.
Because of this, I wrote a small utility that exports the time zone information from a Windows PC to an XML file. My class now takes all of the information from this XML file and not from the registry as William's class does on Windows.
Important: my classes require .NET Framework 3.5. You can get the version for Windows here and the .NET Compact Framework 3.5 here.
These also come with Visual Studio 2008. You can get the free Express edition of Visual Studio straight from Microsoft here.
Without further ado, here are the downloads. I hope you will find them useful.
Source:
Binary:
XML file:
This is an XML file that I exported using my exporter utility on Windows Vista. Download it here.
Sample program:
I have written a sample program using my class. All it does is display the current time in the local time zone, in UTC, and in any other selected time zone. This is meant to run on a Pocket PC. This was tested with the emulator running Windows Mobile 5 and my own Pocket PC running Windows Mobile 6.
- Source code
- Binary - make sure to copy the XML file to the root folder on your Pocket PC for it to work.