问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/9896550/obtaining-the-windows-time-zone-index-when-using-timezoneinfo-getsystemtimezones