Home > C#, C#

.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);

C#, C# ,

Comments

Sanjivani
Sanjivani
12/7/2007 12:30:00 AM #
I want TimeZone conversion from UTC to Indian time not based on Local time.
N M Reddy
N M Reddy
12/16/2007 11: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/9/2009 12:07:06 AM #
Hi,
You don't happen to know when we will get this for Silverlight Smile
1/9/2009 2: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/5/2010 1:54:45 AM #
Pingback from chrisbarba.wordpress.com

How to convert Timezones « Random Technical Thoughts