使用TimeZoneInfo.GetSystemTimeZones()时获取Windows时区索引. [英] obtaining the Windows Time Zone index when using TimeZoneInfo.GetSystemTimeZones();

查看:54
本文介绍了使用TimeZoneInfo.GetSystemTimeZones()时获取Windows时区索引.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在努力的事情是在.net 4(C#)中拉出一个时区列表,以在表单上填充一个下拉列表.我知道我可以做到:

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();

,它将在具有"Id"属性的TimeZoneInfo类中检索时区列表.该ID虽然不是Microsoft时区索引.

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.

例如,对于东部时间,"Id"只是东部标准时间",而内部索引为"35".(其余索引在此处: http://msdn.microsoft.com/en-us/library/ms912391(v=winembedded.11).aspx )

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)

是否有某种方法可以从TimeZoneInfo.GetSystemTimeZones()获取这些索引,或者可以调用一些其他方法来找到那些索引吗?我知道我可以制作一个开关箱或一堆if语句来检查每个ID并匹配一个索引值,但是我认为必须有一种更好的方法.

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.

谢谢!

推荐答案

有些过时,但是

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.

这篇关于使用TimeZoneInfo.GetSystemTimeZones()时获取Windows时区索引.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆