.NET 3.5: How to Convert from one TimeZone to another

23. June 2007

The ability to convert directly from one timezone to another is coming (finally!) in .NET 3.5 via the addition of the System.TimeZoneInfo object.

Example C# Code:
DateTime oldTime = new DateTime(2007, 6, 23, 10, 0, 0);
TimeZoneInfo timeZone1 = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTime newTime = TimeZoneInfo.ConvertTime(oldTime, timeZone1, timeZone2);

General



Comments

Sanjivani
Sanjivani
12/6/2007 10:30:00 PM #
I want TimeZone conversion from UTC to Indian time not based on Local time.
N M Reddy
N M Reddy
12/16/2007 9:26:00 PM #
Hi,
First convert Local Time or required Time to UTC using DateTime.Now.ToUniversalTime(), from there easily you can convert to IST or some other required format.
Tom
Tom
1/8/2009 10:07:06 PM #
Hi,
You don't happen to know when we will get this for Silverlight Smile
1/9/2009 12:39:55 AM #
Tom, I haven't looked as to what Silverlight support for this is planned. You could probably use Reflector to look at the code for the TimeZoneInfo class and write your own simple converter to use in Silverlight.
2/4/2010 11:54:45 PM #
Pingback from chrisbarba.wordpress.com

How to convert Timezones « Random Technical Thoughts
Comments are closed