如何根据国家或州名称查找TimeZoneInfo? [英] How to find TimeZoneInfo based on the Country or State Name?

查看:86
本文介绍了如何根据国家或州名称查找TimeZoneInfo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我获得了CultureInfo Property的国家/地区列表。通过更改国家/地区名称我想获得该国家/地区的UTCTimeZone?是否有可能或以任何其他方式找到基于Country的utcTimeZone

解决方案

您并不是唯一一个希望Microsoft提供了时区列表的人CultureInfo数组中的每个国家/地区都可通过以下方式获取:

 使用 System.Globalization; 

List< CultureInfo> cultures = CultureInfo.GetCultures(CultureTypes.AllCultures).ToList();

或者TimeZoneInfo列表可用:

 List< TimeZoneInfo >  tzList = TimeZoneInfo.GetSystemTimeZones()。ToList(); >  

提供更完整的国家/地区列表名称,并提供了对它们的轻松访问,而不是将它们存储在私有List中,这意味着你必须解析TimeZoneInfo的DisplayName属性。



但是,可能有一些很好的理由(复杂性?夏令时问题?)没有发生。因此,我们必须向MS外面看。



维基百科有关时区的文章[ ^ ]有一个很好的HTML表格,很容易解析,但我不是黑客攻击维基百科。



Noda Time(开源)是我所知道的针对国家/时区映射的最有价值的.NET C#资源:[ ^ ]。



这里有一些关于如何使用Noda Time的好提示:[ ^ ]。


您可以使用一些提供的服务应用程序请求的此信息。如果你进行一些网络搜索,你可以找到一些,例如:

http://www.worldtimeserver.com [ ^ ],

http://www.earthtools.org/webservices.htm#timezone [ ^ ]。



-SA

I get list of countries with CultureInfo Property. By Changing the Country name i want to get the UTCTimeZone for that Country? Is it Possible or any other way is there to find the utcTimeZone based on Country

解决方案

You are not alone in wishing that Microsoft had provided a list of the Time Zones for each Country within the Array of CultureInfo available through:

using System.Globalization;

List<CultureInfo> cultures = CultureInfo.GetCultures(CultureTypes.AllCultures).ToList();

Or that the list of TimeZoneInfo available through:

List<TimeZoneInfo > tzList = TimeZoneInfo.GetSystemTimeZones().ToList();>

Provided a more complete list of country names, and provided easy access to them rather than storing them in a private List which means you have to parse the DisplayName property of the TimeZoneInfo.

But, there's probably some good reasons (complexity ? Daylight Savings Time issues ?) that didn't happen. So, we have to look outside MS.

The Wikipedia article on Time Zones by country [^] has a good HTML table that it's easy to parse, but I am not into hacking Wikipedia.

Noda Time (open-source) is the most .NET C# valuable resource I know of for Country-to-Time-Zone mapping: [^].

There's some good hints on how to use Noda Time here: [^].


You can use some services providing this information on request from applications. You can find some if you do some Web search, for example:
http://www.worldtimeserver.com[^],
http://www.earthtools.org/webservices.htm#timezone[^].

—SA


这篇关于如何根据国家或州名称查找TimeZoneInfo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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