TimeZoneInfo.GetSystemTimeZones() gives you an Enumeration of all the time zones. The question is how to Select entr开发者_StackOverflow社区ies 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.
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?
Regardless, I don't think country code + UTC is going to be easy for these reasons (which you no doubt already know):
Timezones have a many-to-many relationship to countries
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.
The same UTC offset in the same country can yield different timezones
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.
There are often regional differences beyond UTC
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).
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.
How about a bit of Linq magic?
var zones = from tz in TimeZoneInfo.GetSystemTimeZones() where tz.Id = "xxx" select tz;
Replace "xxx" with your desired timezone... :)
精彩评论