Converting GMT dates

I have a DB2 database giving me a date in GMT format and I need to convert it to my local timezone. The .NET TimeZone class makes this sooooo easy:

Dim gmtDate As DateTime = DateTime.Parse(...)
Dim localTime As DateTime = TimeZone.CurrentTimeZone.ToLocalTime(gmtDate)

3 Comments

  • One could event think that this class want designed with DB2 in mind ;-)

  • Yeah, but try converting Eastern Time to Pacific time, or one timezone to another. Then you'll start cursing the framework. Maybe we'll see a component out one day that will do that for us. Arrghh....just venting frustration.

  • I was trying to convert ET(EST/EDT) to GMT and this is the code I used for it.
    Dim tzone As TimeZone = TimeZone.CurrentTimeZone
    Console.WriteLine("{0:yyyy-MM-dd HH:mm:ss G\MT}", tzone.ToUniversalTime(DateTime.Now))

Comments have been disabled for this content.