It seems appropriate to talk about this class, with the switch from Daylight Savings Time to Standard Time occurring this coming weekend in the United States. I’ve done a bit of work with this class lately, and wanted to share a test application I wrote to demonstrate some conversions. It also shows the effects which occur during the actual time change, when converting between time zones. You will need the .NET Framework 3.5 installed to use this demo.

The console application shown here shows how to iterate the defined Time Zones, convert from UTC to the Eastern Time Zone, and Convert from Eastern Time to Pacific Time using UTC as a midpoint in the conversion.  All this is done with the TimeZoneInfo class.  Eastern and Pacific time zones (US) are arbitrary choices: any time zone can be used.

I designed the example times used in the demonstration to show the variances which occur between two times zones, during the actual day of a time change. It also shows the local time ambiguity which occurs during the two occurrences of 2AM in the fall, and the absence of 2AM in the spring.

While the demonstration provides practical examples of how to do these conversions, I hope you will see the value of storing time as UTC instead of its local value in critical applications.  Any time a change occurs, there is a one hour period per year where an occurrence in the 2AM hour will be ambiguous when the date is localized: did it occur before the change or after the change.  If the date recorded is UTC, the ambiguity does not exist.

While most applications can live with one hour of ambiguity in the time per year, especially since it’s a time when most people are asleep, it is an important design consideration in critical applications.