obtaining the Windows Time Zone index when using TimeZoneInfo.GetSystemTimeZones();

老子叫甜甜 提交于 2021-02-07 19:13:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!