Home > .net > Accessing ZoneInfo from Windows

Accessing ZoneInfo from Windows

It’s a well known fact that there’s no direct mapping between Windows timezone ids to standard ids. This could create some problems when one has to support the Olson database in .Net.

In .Net v3.5, a new TimeZoneInfo class was introduced which eased the conversion quite a bit.  One can perform a registry lookup via TimeZoneInfo.FindSystemTimeZoneById and passing in the Windows timezone id that corresponds with the standard TZID from the Windows->Tzid table.

If you’re dealing with older .Net versions, the Public Domain project offers an alternate solution, even though it’s no longer maintained, as noted on the linked page.  As the project contains quite a few classes that perform a myriad of tasks, my recommendation is to rip out the TimeZone classes into a new project. Other key points to keep in mind are mentioned on the related Code Project page:

  • The entire Olson time zone database is compiled into the PublicDomain DLL package. I chose not to use resource files so as not to require FileIOPermission for clients of the package.
    • This increases static initialization time dramatically, and that is the trade off.
  • The TzDatabase class exists primarily at compile time for PublicDomain. When there is a new version of the Olson time zone database, the data files are updated and a script is run which reads the database, converts it to C# code, which is then placed into TzTimeZone.cs and PublicDomain is re-compiled. However, the TzDatabase can be used to get all of the database contents in objectified form, since the database is in an obfuscated form.
  • Advertisements
    Categories: .net Tags:
    1. No comments yet.
    1. August 27, 2009 at 11:31 am
    2. November 6, 2009 at 1:42 pm

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )


    Connecting to %s

    %d bloggers like this: