我想有一个Windows机器上所有可用时区的列表.我怎么能在.NET中这样做?
我知道TimeZoneInfo.GetSystemTimeZones方法,但这只返回当前选定的时区
DateTimeOffset current = DateTimeOffset.Now;
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
Console.WriteLine("You might be in the following time zones:");
foreach (TimeZoneInfo timeZoneInfo in timeZones)
{
// Compare offset with offset for that date in that time zone
if (timeZoneInfo.GetUtcOffset(current).Equals(current.Offset))
{
Console.WriteLine(" {0}", timeZoneInfo.DisplayName);
}
}
Run Code Online (Sandbox Code Playgroud) timezone ×1