5

so something I've been struggling with is pulling a list of time zones in .net 4 (C#) to populate a drop down list on a form. I know I can do this:

var TimeZoneList = TimeZoneInfo.GetSystemTimeZones();

which will retrieve a list of time zones in a TimeZoneInfo class which has an 'Id' property. The ID is not the Microsoft time zone index though.

For example, with eastern time, the 'Id' is simply 'Eastern Standard Time' where as the internal index is '35'. (The rest of the indices are here: http://msdn.microsoft.com/en-us/library/ms912391(v=winembedded.11).aspx)

Is there some way to get these indices from the TimeZoneInfo.GetSystemTimeZones() or is there some other method I can call to find those? I know I can just make a switch case or a bunch of if statements to check each ID and match up an index value, but I'm thinking there has to be a better way.

Thanks!

Seril
  • 499
  • 4
  • 9
  • 22
  • Why do you need to know, out of interest? I would recommend just using the Id to identify the time zone (and retrieve it again) unless you need to interoperate with something which uses the index. – Jon Skeet Mar 27 '12 at 19:46
  • Well I'm developing a web front end to an existing database / application that stores the numerical index in the table. It would be much more of a pain to redesign how that section of the database / application works than just making an extensive if statement. – Seril Mar 27 '12 at 19:50
  • Rather than an `if` statement you could certainly use a dictionary... and probably populate it from the registry. – Jon Skeet Mar 27 '12 at 19:54

1 Answers1

0

It's a little outdated, but this MSDN forum posting from 2008 (.NET 3.5) suggests that a good mapping does not exist and perhaps you should create a cross reference table from TimeZoneInfo IDs to the Time Zone Ids from the page you point to.

Steve Danner
  • 21,818
  • 7
  • 41
  • 51