相关疑难解决方法(0)

如何枚举.NET中的所有时区?

我想有一个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

26
推荐指数
2
解决办法
1万
查看次数

标签 统计

timezone ×1