About the author

Vijay Kodali
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024

Convert time from one timezone to another timezone in Asp.Net

Handling timzone is quite simple in Asp.Net applications. First thing,   you should always store DateTime values in the DB in one timezone (UTC is most commonly used).  This eliminates many conversion issues.


Here is the sample code..

DateTime time1 = new DateTime(2008, 12, 11, 6, 0, 0);  // your DataTimeVariable 
TimeZoneInfo timeZone1 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); 
TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"); 
DateTime newTime = TimeZoneInfo.ConvertTime(time1, timeZone1, timeZone2);

Get all available/supported Timezones in .Net TimeZoneInfo class

      foreach (var tz in TimeZoneInfo.GetSystemTimeZones())
            {
                Response.Write(tz.DisplayName + " is Id =','" + tz.Id + "'");
                Response.Write("<br>");
            }


Posted by Vijay on Wednesday, January 6, 2010 8:24 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading