0 comments suggest edit

TimeZones Right now, there is no easy way to convert a time from one arbitrary timezone to another arbitrary timezone in .NET.  Certainly you can convert from UTC to the local system time, or from the local system time to UTC. But how do you convert from PST to EST?

Well Scott Hanselman recently pointed me to some ingenious code in DasBlog originally written by Clemens Vasters that does this.  I recently submitted a patch to DasBlog so that this code properly handles daylight savings and I had planned to blog about it in more detail later.  Unfortunately, we recently found out that changes in Vista may break this particular approach.

It turns out that the Orcas release introduces a new TimeZone2 class.  This class will finally allow conversions between arbitrary timezones.

Krzysztof Cwalina (who wins the award for Microsoft blogger with the highest consonants to vowel ration in a first name) points out that many people are not thrilled with the “2” suffix and provides context on the naming choice

Kathy Kam of the BCL team points out some other proposed names for the new TimeZone2 class and the problems with each.

I’m fine with TimeZone2 or TimeZoneRegion.


Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.



8 responses

  1. Avatar for Darren Neimke
    Darren Neimke October 6th, 2006

    Hi Phil, there are some Timezone smarts in SUB too. I actually implemented and extended some functionality that I found in this article:
    Unfortunately it requires high trust because it reads the timezone information from the Windows Registry location:
    SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones

  2. Avatar for Haacked
    Haacked October 6th, 2006

    The Dasblog code does the same thing, but they also serialized the timezone info into XML and then embedded that XML doc, just in case permission is not granted.
    That was a stroke of genius.

  3. Avatar for vikram
    vikram October 6th, 2006

    Interesting. Never looked into this before, But certionaly a great feature and would like the name to be TimeZoneManager

  4. Avatar for jayson knight
    jayson knight October 6th, 2006

    About dizzamn time...long overdue. Rolling this stuff by hand is so 20th century.

  5. Avatar for Michal Chaniewski
    Michal Chaniewski October 6th, 2006

    Interesting story and it's good to know about the new class. I'll be needing that very soon :)
    By the way, 'rz' and 'sz' are in fact single sounds (rz reads like -ge in 'collage', and sz reads like -sh in 'Polish'). So Krzysztof's name is in fact a bit simpler than it looks like ;)

  6. Avatar for jayson knight
    jayson knight October 7th, 2006

    Michal, yeah...easy if you're Polish ;-). Then again, I still struggle w/ Dziekuje (missing two diacratics over both e's which makes them nasal sounding).

  7. Avatar for StevenHarman.net
    StevenHarman.net December 17th, 2006

    Hotfix KB928388 - Revised Daylight Savings Time

  8. Avatar for Steve Pratt
    Steve Pratt July 23rd, 2010

    It is very easy to convert to different timezones.
    z/OS (formerly os-390 and MVS) maintains not only the current local time but also the offset from UTC. For example, Central Daylight Time is -5 hours 0 minutes from UTC. It is 14:00 CDT & it is 19:00 UTC.
    All application programs running on z/OS can access this value.
    DB2 calls this value "current timezone", much like it calls the clock "current time." It is a good practice to always store the timezone whenever one stores the time. I would store 14:00 as the time and -50000 as the timezone. (the zeroes show minutes and seconds. I realize the seconds are not needed, but DB2 stores timezone as Decimal(6,0).)