Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Thursday, October 05, 2006

.NET System.TimeZone2 Starter Guide

.NET System.TimeZone2 Starter Guide

Extended Time Zone support is one of the most requested features in the BCL. System.TimeZone provides some basic support for converting from your machine Time Zone to UTC and vice versa, but it doesn’t have support to convert… say from Pacific Standard Time to Eastern Standard Time. In the “Orcas” September CTP, you’ll see that the BCL team has added a new class named “System.TimeZone2” that will allow you to:

-          Convert a DateTime from one time zone (not necessarily your machine’s time zone) to another

-          Get an object that describes your local time zone

-          Get an array of objects that describes all the available time zones on your machine

-          Serialize a time zone into a string

-          Create your own time zone object to represent any custom time zones


The best part about this is that… if you are on an Vista machine… all of those functionality will have Vista’s Dynamic Time Zone support, because our calculations are done with the time zone data available on your OS.


Without further ado, let me start by showing you some samples:


1)    Getting the Local time zone on your machine:

TimeZone2 GetLocalTimeZone()
    return TimeZone2.Local;

.NET System.TimeZone2 Starter Guide

Post a Comment