TimeZoneInfo.GetSystemTimeZones()如何选择具体的国家codeS仅录?如何选择、具体、国家、TimeZoneInfo

2023-09-04 00:46:23 作者:? 正在缓冲99%

TimeZoneInfo.GetSystemTimeZones()给你所有时区的一个枚举。现在的问题是如何选择具体的国家codeS唯一条目。我知道UTC偏移和国家code和需要能够选择正确的时区值。

TimeZoneInfo.GetSystemTimeZones() gives you an Enumeration of all the time zones. The question is how to Select entries for specific country codes only. I know the UTC offset and the country code and need to be able to select the correct time zone value.

推荐答案

首先,你会发现,你不能简单地使用(除也许是其他区域差)的UTC由于夏令变化所抵消。也许,如果你提供的UTC偏移量是当前偏移,而你是定期轮询它,你可以只用这个?

First, you would have discovered you can't simply use the UTC offset due to Daylight Savings variations (among perhaps other regional deviations). Perhaps if your provided UTC offset is the current offset, and you are regularly polling it, you could just use this?

无论如何,我不认为国家code + UTC是一件容易的事出于这些原因(你毫无疑问已经知道了):

Regardless, I don't think country code + UTC is going to be easy for these reasons (which you no doubt already know):

时区有许多一对多的关系,国家

在东京标准时间是最有可能只是日本(或者至少,JP和UTC + 9:00可以concievably给您东京标准时间),什么是中亚标准时间?当然,如果你有每个国家的每一个时区的地图,你也许能够得到的地方在这里。

While "Tokyo Standard Time" is most likely just Japan (or at least, "JP" and UTC+9:00 could concievably give you Tokyo Standard Time), what about "Central Asia Standard Time"? Sure, if you had a map of every country to every timezone you might be able to get somewhere here.

同样UTC在同一个国家的偏移会产生不同的时区

例如,在澳大利亚,昆士兰州(布里斯班)不遵守夏令时,而其他东部各州做。这就产生了E.澳大利亚标准时间和澳大利亚东部标准时间作为单独的时区与同一国家和UTC偏移量。

For instance, in Australia, Queensland (Brisbane) does not observe Daylight Savings Time, whereas the other Eastern states do. This yields "E. Australia Standard Time" and "AUS Eastern Standard Time" as seperate timezones with the same country and UTC offset.

有超过UTC通常是区域性的差异

这些可能不是你一个问题,由于其较低的相关性(我不知道如何precise你的用例就是),但也有异常现象,如在多个时区而妥协的边境城镇UTC平均或类似。这方面的一个例子是中央西部标准时间(http://basementgeographer.blogspot.com/2010/07/central-western-standard-time-time-zone.html).

These are probably not a concern for you due to their low relevance (and I'm not sure how precise your usecase is), but there are anomalies such as towns on the borders of multiple timezones which compromise for an "averaged UTC" or similar. An example of this is "Central Western Standard Time" (http://basementgeographer.blogspot.com/2010/07/central-western-standard-time-time-zone.html).

不过,您可能会发现这个问题的存在(国时区映射数据库)利益,这将产生此链接( http://www.twinsun.com/tz/tz-link.htm )。假设你有足够的提供的信息您可以使用此数据来解决一个时区,或者至少是一个最好的猜测(从可能的选项或查询用户?)如果这仍然是有用的/有可能。

However, you may find this existing question (Country to Timezone mapping database) of interest, which yields this link (http://www.twinsun.com/tz/tz-link.htm). Assuming you have enough provided information you may be able to resolve a timezone using this data, or at least a best guess (or query user from possible options?) if that is still useful/possible.