TimeZones

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.

 

Tags: , ,

What others have said

Requesting Gravatar... Darren Neimke Oct 06, 2006 6:49 PM
# re: TimeZones
Hi Phil, there are some Timezone smarts in SUB too. I actually implemented and extended some functionality that I found in this article:

http://www.codeproject.com/dotnet/WorldClock.asp

Unfortunately it requires high trust because it reads the timezone information from the Windows Registry location:

SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones
Requesting Gravatar... Haacked Oct 06, 2006 6:57 PM
# re: TimeZones
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.
Requesting Gravatar... vikram Oct 06, 2006 9:55 PM
# re: TimeZones
Interesting. Never looked into this before, But certionaly a great feature and would like the name to be TimeZoneManager
Requesting Gravatar... jayson knight Oct 06, 2006 11:59 PM
# re: TimeZones
About dizzamn time...long overdue. Rolling this stuff by hand is so 20th century.
Requesting Gravatar... Michal Chaniewski Oct 07, 2006 1:24 AM
# re: TimeZones
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 ;)
Requesting Gravatar... jayson knight Oct 07, 2006 10:25 PM
# re: TimeZones
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).
Requesting Gravatar... StevenHarman.net Dec 18, 2006 9:42 AM
# Hotfix KB928388 - Revised Daylight Savings Time
Hotfix KB928388 - Revised Daylight Savings Time
Requesting Gravatar... Steve Pratt Jul 23, 2010 12:15 PM
# re: TimeZones
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).)

What do you have to say?

(will show your gravatar)
Please add 1 and 8 and type the answer here: