与C#中的FindTimeZoneById()一起使用的时区ID列表?


253

有人可以给我指出ID中预期的ID所引用的所有时区的完整列表TimeZoneInfo.FindTimeZoneById()吗?我在任何地方都找不到列表,并且已经浏览了.NET文档。


2
如果您在下面的答案中注意到有几个令人困惑的重复时区ID,则应阅读此处以了解更多信息:stackoverflow.com/a/15448800/37055
Chris Marisic

7
重要 -此数据不是静态的。随着世界各国政府的变化,Windows引入了新的时区。最终,这就是为什么文档中没有列出它们的权威页面的原因。不要依赖任何硬编码的列表,而要自称TimeZoneInfo.FindTimeZoneById()或使用TZUTIL.EXE /L它们来列出它们。以下答案只是报告数据时的快照。 请勿从此处复制代码到您的应用程序中!
马特·约翰逊

1
如果需要,您可以从注册表中读取HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones,或使用EnumDynamicTimeZoneInformationWindows API。
马特·约翰逊

Answers:


357

这是程序及其结果的完整列表。

代码:

using System;

namespace TimeZoneIds
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
                Console.WriteLine(z.Id);
        }
    }
}

TimeZoneId我的Windows 7工作站的结果:

截止日期标准时间

UTC-11

萨摩亚标准时间

夏威夷标准时间

阿拉斯加标准时间

太平洋标准时间(墨西哥)

太平洋标准时间

美国山区标准时间

山区标准时间(墨西哥)

山区标准时间

中美洲标准时间

中部标准时间

中部标准时间(墨西哥)

加拿大中部标准时间

南太平洋标准时间

东部标准时间

美国东部标准时间

委内瑞拉标准时间

巴拉圭标准时间

大西洋标准时间

巴西中部标准时间

SA Western Standard Time

太平洋标准时间

纽芬兰标准时间

E.南美标准时间

阿根廷标准时间

SA东部标准时间

格陵兰标准时间

蒙得维的亚标准时间

UTC-02

大西洋中部标准时间

亚速尔群岛标准时间

佛得角标准时间

摩洛哥标准时间

世界标准时间

格林尼治标准时间

格林威治标准时间

W.欧洲标准时间

中欧标准时间

浪漫标准时间

中欧标准时间

W.中非标准时间

纳米比亚标准时间

约旦标准时间

GTB标准时间

中东标准时间

埃及标准时间

叙利亚标准时间

南非标准时间

FLE标准时间

以色列标准时间

E.欧洲标准时间

阿拉伯标准时间

阿拉伯标准时间

俄罗斯标准时间

E.非洲标准时间

伊朗标准时间

阿拉伯标准时间

阿塞拜疆标准时间

毛里求斯标准时间

格鲁吉亚标准时间

高加索标准时间

阿富汗标准时间

叶卡捷琳堡标准时间

巴基斯坦标准时间

西亚标准时间

印度标准时间

斯里兰卡标准时间

尼泊尔标准时间

中亚标准时间

孟加拉国标准时间

N.中亚标准时间

缅甸标准时间

东南亚标准时间

北亚标准时间

中国标准时间

北亚东部标准时间

新加坡标准时间

W.澳大利亚标准时间

台北标准时间

乌兰巴托标准时间

东京标准时间

韩国标准时间

雅库茨克标准时间

岑 澳大利亚标准时间

澳大利亚中央标准时间

E.澳大利亚标准时间

澳大利亚东部标准时间

西太平洋标准时间

塔斯马尼亚标准时间

海参div标准时间

中太平洋标准时间

新西兰标准时间

UTC + 12

斐济标准时间

堪察加标准时间

汤加标准时间


7
此列表的输出是否对您当前是否处于夏令时敏感?否则,名称似乎不正确。东部标准时间是一年中大部分时间的格林尼治标准时间-5,但格林尼治标准时间-4。
JohnOpincar 2013年

4
是的,TimeZoneInfo.FindSystemTimeZoneById方法对夏令时敏感...请参阅msdn.microsoft.com/zh-CN/library/…。它指出:“然后使用此TimeZoneInfo对象将本地时间转换为东京的时间,并确定它是东京标准时间还是东京夏令时间。”
塞巴斯蒂安2014年

25
@JohnOpincar-你是正确的。ID名称具有误导性。“东部标准时间”代表两个 EST和EDT。
马特·约翰逊·品脱

6
@ Sebastian-为避免混淆,我认为您的第一句话应为:“否,程序的输出对夏令时不敏感。” 无论一年中什么时候运行该程序,列表都会相同,这正是JohnOpincar所要求的。
TTT

6
注意:时区名称对操作系统敏感。Windows Server 2008和Windows Server 2012具有不同的列表。
Ross Presser

92

如果您想要HTML,请选择Windows时区:

<select>
<option value="Morocco Standard Time">(GMT) Casablanca</option>
<option value="GMT Standard Time">(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London</option>
<option value="Greenwich Standard Time">(GMT) Monrovia, Reykjavik</option>
<option value="W. Europe Standard Time">(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna</option>
<option value="Central Europe Standard Time">(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague</option>
<option value="Romance Standard Time">(GMT+01:00) Brussels, Copenhagen, Madrid, Paris</option>
<option value="Central European Standard Time">(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb</option>
<option value="W. Central Africa Standard Time">(GMT+01:00) West Central Africa</option>
<option value="Jordan Standard Time">(GMT+02:00) Amman</option>
<option value="GTB Standard Time">(GMT+02:00) Athens, Bucharest, Istanbul</option>
<option value="Middle East Standard Time">(GMT+02:00) Beirut</option>
<option value="Egypt Standard Time">(GMT+02:00) Cairo</option>
<option value="South Africa Standard Time">(GMT+02:00) Harare, Pretoria</option>
<option value="FLE Standard Time">(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius</option>
<option value="Israel Standard Time">(GMT+02:00) Jerusalem</option>
<option value="E. Europe Standard Time">(GMT+02:00) Minsk</option>
<option value="Namibia Standard Time">(GMT+02:00) Windhoek</option>
<option value="Arabic Standard Time">(GMT+03:00) Baghdad</option>
<option value="Arab Standard Time">(GMT+03:00) Kuwait, Riyadh</option>
<option value="Russian Standard Time">(GMT+03:00) Moscow, St. Petersburg, Volgograd</option>
<option value="E. Africa Standard Time">(GMT+03:00) Nairobi</option>
<option value="Georgian Standard Time">(GMT+03:00) Tbilisi</option>
<option value="Iran Standard Time">(GMT+03:30) Tehran</option>
<option value="Arabian Standard Time">(GMT+04:00) Abu Dhabi, Muscat</option>
<option value="Azerbaijan Standard Time">(GMT+04:00) Baku</option>
<option value="Mauritius Standard Time">(GMT+04:00) Port Louis</option>
<option value="Caucasus Standard Time">(GMT+04:00) Yerevan</option>
<option value="Afghanistan Standard Time">(GMT+04:30) Kabul</option>
<option value="Ekaterinburg Standard Time">(GMT+05:00) Ekaterinburg</option>
<option value="Pakistan Standard Time">(GMT+05:00) Islamabad, Karachi</option>
<option value="West Asia Standard Time">(GMT+05:00) Tashkent</option>
<option value="India Standard Time">(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi</option>
<option value="Sri Lanka Standard Time">(GMT+05:30) Sri Jayawardenepura</option>
<option value="Nepal Standard Time">(GMT+05:45) Kathmandu</option>
<option value="N. Central Asia Standard Time">(GMT+06:00) Almaty, Novosibirsk</option>
<option value="Central Asia Standard Time">(GMT+06:00) Astana, Dhaka</option>
<option value="Myanmar Standard Time">(GMT+06:30) Yangon (Rangoon)</option>
<option value="SE Asia Standard Time">(GMT+07:00) Bangkok, Hanoi, Jakarta</option>
<option value="North Asia Standard Time">(GMT+07:00) Krasnoyarsk</option>
<option value="China Standard Time">(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi</option>
<option value="North Asia East Standard Time">(GMT+08:00) Irkutsk, Ulaan Bataar</option>
<option value="Singapore Standard Time">(GMT+08:00) Kuala Lumpur, Singapore</option>
<option value="W. Australia Standard Time">(GMT+08:00) Perth</option>
<option value="Taipei Standard Time">(GMT+08:00) Taipei</option>
<option value="Tokyo Standard Time">(GMT+09:00) Osaka, Sapporo, Tokyo</option>
<option value="Korea Standard Time">(GMT+09:00) Seoul</option>
<option value="Yakutsk Standard Time">(GMT+09:00) Yakutsk</option>
<option value="Cen. Australia Standard Time">(GMT+09:30) Adelaide</option>
<option value="AUS Central Standard Time">(GMT+09:30) Darwin</option>
<option value="E. Australia Standard Time">(GMT+10:00) Brisbane</option>
<option value="AUS Eastern Standard Time">(GMT+10:00) Canberra, Melbourne, Sydney</option>
<option value="West Pacific Standard Time">(GMT+10:00) Guam, Port Moresby</option>
<option value="Tasmania Standard Time">(GMT+10:00) Hobart</option>
<option value="Vladivostok Standard Time">(GMT+10:00) Vladivostok</option>
<option value="Central Pacific Standard Time">(GMT+11:00) Magadan, Solomon Is., New Caledonia</option>
<option value="New Zealand Standard Time">(GMT+12:00) Auckland, Wellington</option>
<option value="Fiji Standard Time">(GMT+12:00) Fiji, Kamchatka, Marshall Is.</option>
<option value="Tonga Standard Time">(GMT+13:00) Nuku'alofa</option>
<option value="Azores Standard Time">(GMT-01:00) Azores</option>
<option value="Cape Verde Standard Time">(GMT-01:00) Cape Verde Is.</option>
<option value="Mid-Atlantic Standard Time">(GMT-02:00) Mid-Atlantic</option>
<option value="E. South America Standard Time">(GMT-03:00) Brasilia</option>
<option value="Argentina Standard Time">(GMT-03:00) Buenos Aires</option>
<option value="SA Eastern Standard Time">(GMT-03:00) Georgetown</option>
<option value="Greenland Standard Time">(GMT-03:00) Greenland</option>
<option value="Montevideo Standard Time">(GMT-03:00) Montevideo</option>
<option value="Newfoundland Standard Time">(GMT-03:30) Newfoundland</option>
<option value="Atlantic Standard Time">(GMT-04:00) Atlantic Time (Canada)</option>
<option value="SA Western Standard Time">(GMT-04:00) La Paz</option>
<option value="Central Brazilian Standard Time">(GMT-04:00) Manaus</option>
<option value="Pacific SA Standard Time">(GMT-04:00) Santiago</option>
<option value="Venezuela Standard Time">(GMT-04:30) Caracas</option>
<option value="SA Pacific Standard Time">(GMT-05:00) Bogota, Lima, Quito, Rio Branco</option>
<option value="Eastern Standard Time">(GMT-05:00) Eastern Time (US & Canada)</option>
<option value="US Eastern Standard Time">(GMT-05:00) Indiana (East)</option>
<option value="Central America Standard Time">(GMT-06:00) Central America</option>
<option value="Central Standard Time">(GMT-06:00) Central Time (US & Canada)</option>
<option value="Central Standard Time (Mexico)">(GMT-06:00) Guadalajara, Mexico City, Monterrey</option>
<option value="Canada Central Standard Time">(GMT-06:00) Saskatchewan</option>
<option value="US Mountain Standard Time">(GMT-07:00) Arizona</option>
<option value="Mountain Standard Time (Mexico)">(GMT-07:00) Chihuahua, La Paz, Mazatlan</option>
<option value="Mountain Standard Time">(GMT-07:00) Mountain Time (US & Canada)</option>
<option value="Pacific Standard Time">(GMT-08:00) Pacific Time (US & Canada)</option>
<option value="Pacific Standard Time (Mexico)">(GMT-08:00) Tijuana, Baja California</option>
<option value="Alaskan Standard Time">(GMT-09:00) Alaska</option>
<option value="Hawaiian Standard Time">(GMT-10:00) Hawaii</option>
<option value="Samoa Standard Time">(GMT-11:00) Midway Island, Samoa</option>
<option value="Dateline Standard Time">(GMT-12:00) International Date Line West</option>
</select>

而且,如果您想在Razor视图中的C#.NET MVC中使用它:

var timezones = new List<SelectListItem> { 
new SelectListItem() { Value="", Text="Select timezone...", Selected = false },
new SelectListItem() { Value="Morocco Standard Time", Text="(GMT) Casablanca", Selected = false },
new SelectListItem() { Value="GMT Standard Time", Text="(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London", Selected = false },
new SelectListItem() { Value="Greenwich Standard Time", Text="(GMT) Monrovia, Reykjavik", Selected = false },
new SelectListItem() { Value="W. Europe Standard Time", Text="(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna", Selected = false },
new SelectListItem() { Value="Central Europe Standard Time", Text="(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague", Selected = false },
new SelectListItem() { Value="Romance Standard Time", Text="(GMT+01:00) Brussels, Copenhagen, Madrid, Paris", Selected = false },
new SelectListItem() { Value="Central European Standard Time", Text="(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb", Selected = false },
new SelectListItem() { Value="W. Central Africa Standard Time", Text="(GMT+01:00) West Central Africa", Selected = false },
new SelectListItem() { Value="Jordan Standard Time", Text="(GMT+02:00) Amman", Selected = false },
new SelectListItem() { Value="GTB Standard Time", Text="(GMT+02:00) Athens, Bucharest, Istanbul", Selected = false },
new SelectListItem() { Value="Middle East Standard Time", Text="(GMT+02:00) Beirut", Selected = false },
new SelectListItem() { Value="Egypt Standard Time", Text="(GMT+02:00) Cairo", Selected = false },
new SelectListItem() { Value="South Africa Standard Time", Text="(GMT+02:00) Harare, Pretoria", Selected = false },
new SelectListItem() { Value="FLE Standard Time", Text="(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius", Selected = false },
new SelectListItem() { Value="Israel Standard Time", Text="(GMT+02:00) Jerusalem", Selected = false },
new SelectListItem() { Value="E. Europe Standard Time", Text="(GMT+02:00) Minsk", Selected = false },
new SelectListItem() { Value="Namibia Standard Time", Text="(GMT+02:00) Windhoek", Selected = false },
new SelectListItem() { Value="Arabic Standard Time", Text="(GMT+03:00) Baghdad", Selected = false },
new SelectListItem() { Value="Arab Standard Time", Text="(GMT+03:00) Kuwait, Riyadh", Selected = false },
new SelectListItem() { Value="Russian Standard Time", Text="(GMT+03:00) Moscow, St. Petersburg, Volgograd", Selected = false },
new SelectListItem() { Value="E. Africa Standard Time", Text="(GMT+03:00) Nairobi", Selected = false },
new SelectListItem() { Value="Georgian Standard Time", Text="(GMT+03:00) Tbilisi", Selected = false },
new SelectListItem() { Value="Iran Standard Time", Text="(GMT+03:30) Tehran", Selected = false },
new SelectListItem() { Value="Arabian Standard Time", Text="(GMT+04:00) Abu Dhabi, Muscat", Selected = false },
new SelectListItem() { Value="Azerbaijan Standard Time", Text="(GMT+04:00) Baku", Selected = false },
new SelectListItem() { Value="Mauritius Standard Time", Text="(GMT+04:00) Port Louis", Selected = false },
new SelectListItem() { Value="Caucasus Standard Time", Text="(GMT+04:00) Yerevan", Selected = false },
new SelectListItem() { Value="Afghanistan Standard Time", Text="(GMT+04:30) Kabul", Selected = false },
new SelectListItem() { Value="Ekaterinburg Standard Time", Text="(GMT+05:00) Ekaterinburg", Selected = false },
new SelectListItem() { Value="Pakistan Standard Time", Text="(GMT+05:00) Islamabad, Karachi", Selected = false },
new SelectListItem() { Value="West Asia Standard Time", Text="(GMT+05:00) Tashkent", Selected = false },
new SelectListItem() { Value="India Standard Time", Text="(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi", Selected = false },
new SelectListItem() { Value="Sri Lanka Standard Time", Text="(GMT+05:30) Sri Jayawardenepura", Selected = false },
new SelectListItem() { Value="Nepal Standard Time", Text="(GMT+05:45) Kathmandu", Selected = false },
new SelectListItem() { Value="N. Central Asia Standard Time", Text="(GMT+06:00) Almaty, Novosibirsk", Selected = false },
new SelectListItem() { Value="Central Asia Standard Time", Text="(GMT+06:00) Astana, Dhaka", Selected = false },
new SelectListItem() { Value="Myanmar Standard Time", Text="(GMT+06:30) Yangon (Rangoon)", Selected = false },
new SelectListItem() { Value="SE Asia Standard Time", Text="(GMT+07:00) Bangkok, Hanoi, Jakarta", Selected = false },
new SelectListItem() { Value="North Asia Standard Time", Text="(GMT+07:00) Krasnoyarsk", Selected = false },
new SelectListItem() { Value="China Standard Time", Text="(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi", Selected = false },
new SelectListItem() { Value="North Asia East Standard Time", Text="(GMT+08:00) Irkutsk, Ulaan Bataar", Selected = false },
new SelectListItem() { Value="Singapore Standard Time", Text="(GMT+08:00) Kuala Lumpur, Singapore", Selected = false },
new SelectListItem() { Value="W. Australia Standard Time", Text="(GMT+08:00) Perth", Selected = false },
new SelectListItem() { Value="Taipei Standard Time", Text="(GMT+08:00) Taipei", Selected = false },
new SelectListItem() { Value="Tokyo Standard Time", Text="(GMT+09:00) Osaka, Sapporo, Tokyo", Selected = false },
new SelectListItem() { Value="Korea Standard Time", Text="(GMT+09:00) Seoul", Selected = false },
new SelectListItem() { Value="Yakutsk Standard Time", Text="(GMT+09:00) Yakutsk", Selected = false },
new SelectListItem() { Value="Cen. Australia Standard Time", Text="(GMT+09:30) Adelaide", Selected = false },
new SelectListItem() { Value="AUS Central Standard Time", Text="(GMT+09:30) Darwin", Selected = false },
new SelectListItem() { Value="E. Australia Standard Time", Text="(GMT+10:00) Brisbane", Selected = false },
new SelectListItem() { Value="AUS Eastern Standard Time", Text="(GMT+10:00) Canberra, Melbourne, Sydney", Selected = false },
new SelectListItem() { Value="West Pacific Standard Time", Text="(GMT+10:00) Guam, Port Moresby", Selected = false },
new SelectListItem() { Value="Tasmania Standard Time", Text="(GMT+10:00) Hobart", Selected = false },
new SelectListItem() { Value="Vladivostok Standard Time", Text="(GMT+10:00) Vladivostok", Selected = false },
new SelectListItem() { Value="Central Pacific Standard Time", Text="(GMT+11:00) Magadan, Solomon Is., New Caledonia", Selected = false },
new SelectListItem() { Value="New Zealand Standard Time", Text="(GMT+12:00) Auckland, Wellington", Selected = false },
new SelectListItem() { Value="Fiji Standard Time", Text="(GMT+12:00) Fiji, Kamchatka, Marshall Is.", Selected = false },
new SelectListItem() { Value="Tonga Standard Time", Text="(GMT+13:00) Nuku'alofa", Selected = false },
new SelectListItem() { Value="Azores Standard Time", Text="(GMT-01:00) Azores", Selected = false },
new SelectListItem() { Value="Cape Verde Standard Time", Text="(GMT-01:00) Cape Verde Is.", Selected = false },
new SelectListItem() { Value="Mid-Atlantic Standard Time", Text="(GMT-02:00) Mid-Atlantic", Selected = false },
new SelectListItem() { Value="E. South America Standard Time", Text="(GMT-03:00) Brasilia", Selected = false },
new SelectListItem() { Value="Argentina Standard Time", Text="(GMT-03:00) Buenos Aires", Selected = false },
new SelectListItem() { Value="SA Eastern Standard Time", Text="(GMT-03:00) Georgetown", Selected = false },
new SelectListItem() { Value="Greenland Standard Time", Text="(GMT-03:00) Greenland", Selected = false },
new SelectListItem() { Value="Montevideo Standard Time", Text="(GMT-03:00) Montevideo", Selected = false },
new SelectListItem() { Value="Newfoundland Standard Time", Text="(GMT-03:30) Newfoundland", Selected = false },
new SelectListItem() { Value="Atlantic Standard Time", Text="(GMT-04:00) Atlantic Time (Canada)", Selected = false },
new SelectListItem() { Value="SA Western Standard Time", Text="(GMT-04:00) La Paz", Selected = false },
new SelectListItem() { Value="Central Brazilian Standard Time", Text="(GMT-04:00) Manaus", Selected = false },
new SelectListItem() { Value="Pacific SA Standard Time", Text="(GMT-04:00) Santiago", Selected = false },
new SelectListItem() { Value="Venezuela Standard Time", Text="(GMT-04:30) Caracas", Selected = false },
new SelectListItem() { Value="SA Pacific Standard Time", Text="(GMT-05:00) Bogota, Lima, Quito, Rio Branco", Selected = false },
new SelectListItem() { Value="Eastern Standard Time", Text="(GMT-05:00) Eastern Time (US & Canada)", Selected = false },
new SelectListItem() { Value="US Eastern Standard Time", Text="(GMT-05:00) Indiana (East)", Selected = false },
new SelectListItem() { Value="Central America Standard Time", Text="(GMT-06:00) Central America", Selected = false },
new SelectListItem() { Value="Central Standard Time", Text="(GMT-06:00) Central Time (US & Canada)", Selected = false },
new SelectListItem() { Value="Central Standard Time (Mexico)", Text="(GMT-06:00) Guadalajara, Mexico City, Monterrey", Selected = false },
new SelectListItem() { Value="Canada Central Standard Time", Text="(GMT-06:00) Saskatchewan", Selected = false },
new SelectListItem() { Value="US Mountain Standard Time", Text="(GMT-07:00) Arizona", Selected = false },
new SelectListItem() { Value="Mountain Standard Time (Mexico)", Text="(GMT-07:00) Chihuahua, La Paz, Mazatlan", Selected = false },
new SelectListItem() { Value="Mountain Standard Time", Text="(GMT-07:00) Mountain Time (US & Canada)", Selected = false },
new SelectListItem() { Value="Pacific Standard Time", Text="(GMT-08:00) Pacific Time (US & Canada)", Selected = false },
new SelectListItem() { Value="Pacific Standard Time (Mexico)", Text="(GMT-08:00) Tijuana, Baja California", Selected = false },
new SelectListItem() { Value="Alaskan Standard Time", Text="(GMT-09:00) Alaska", Selected = false },
new SelectListItem() { Value="Hawaiian Standard Time", Text="(GMT-10:00) Hawaii", Selected = false },
new SelectListItem() { Value="Samoa Standard Time", Text="(GMT-11:00) Midway Island, Samoa", Selected = false },
new SelectListItem() { Value="Dateline Standard Time", Text="(GMT-12:00) International Date Line West", Selected = false }
}

尽管对于Razor,您当然可以通过循环生成选项 TimeZoneInfo.GetSystemTimeZones()


您是否有生成此列表的代码?我想知道您如何输出GMT部分。
Jeson Martajaya 2014年

45
如果可以通过var allTimeZones = TimeZoneInfo.GetSystemTimeZones();获取列表,为什么还要对列表进行硬编码????
HelloWorld

6
对列表进行硬编码有可能遗漏随时间增加的完美有效值!这不是一个好主意。
ErikE

2
硬编码到视图中似乎是一个非常糟糕的主意。容易出现人为错误并难以维持。
萨拉

1
它(.NET代码)已添加到此处,因此可以对其进行剪切和粘贴,从而最大程度地减少人为错误。话虽如此,该解决方案还建议循环遍历TimeZoneInfo.GetSystemTimeZones()。不确定时区定义的更改频率(以及此类更改是否立即反映在.NET中),因此不确定实际需要多少“维护”。
ProfNimrod '16


8

MSDN

ReadOnlyCollection<TimeZoneInfo> zones = TimeZoneInfo.GetSystemTimeZones();
Console.WriteLine("The local system has the following {0} time zones", zones.Count);
foreach (TimeZoneInfo zone in zones)
   Console.WriteLine(zone.Id);

4
那不是它们的列表...我不想在任何我想使用它们的时候都去编程地列出它们。
托马斯(Thomas)

1
@ user976921:这为您提供了由本地计算机定义的列表。您甚至可以定义自定义列表,因此我不确定您可能想要的列表的综合程度如何。
马克

@ user976921:运行Marc的代码,然后从输出窗口复制到文本文件。
MusiGenesis'Oct

1
如果我编写一个程序来输出它们,这将给我一个列表。问题是我想要一个可以快速引用的列表,而不必每次都向我展示它们时就跟上程序。我只想要一个快速参考链接,我可以随时访问并查看完整的完整列表。
托马斯(Thomas)

linqpad的@Marc +1 ...以前从未听说过,但看起来非常有用!谢谢!
Paccc

8

您将GMToffsets 在此处找到时区的完整列表,并且可以使用“时区名称”列值通过ID查找时区

例如

TimeZoneInfo objTimeZoneInfo = TimeZoneInfo.FindTimeZoneById("Dateline Standard Time");

您将获得时区信息类,其中包含用于GMT-12:00的日期线标准时区。


而是TimeZoneInfo.FindSystemTimeZoneById。
Stuart Hallows 2013年

奇怪的是,在称为“此处”的页面(msdn.microsoft.com/en-us/library/…)上,该列表可能不完整,但不正确。请查看有问题的孩子Arizona(US)的条目。页面上的条目显示“ US Mountain Standard Time”,但如果您在FindTimeZoneById中使用该值,则会导致TimeZoneNotFoundException。如果您检查上面的程序输出,您会看到正确的值是“美国山区标准时间”(无句点)。似乎页面上的值在某些时候被“清理”了,无法信任。
Anne Gunn 2015年

8

这是我从ProfNimrod的答案转换而来的Json版本...

{
    tZCode : "Morocco Standard Time",
    tZDesc : "(GMT) Casablanca"
},
{
    tZCode : "GMT Standard Time",
    tZDesc : "(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London"
},
{
    tZCode : "Greenwich Standard Time",
    tZDesc : "(GMT) Monrovia, Reykjavik"
},
{
    tZCode : "W. Europe Standard Time",
    tZDesc : "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna"
},
{
    tZCode : "Central Europe Standard Time",
    tZDesc : "(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague"
},
{
    tZCode : "Romance Standard Time",
    tZDesc : "(GMT+01:00) Brussels, Copenhagen, Madrid, Paris"
},
{
    tZCode : "Central European Standard Time",
    tZDesc : "(GMT+01:00) Sarajevo, Skopje, Warsaw, Zagreb"
},
{
    tZCode : "W. Central Africa Standard Time",
    tZDesc : "(GMT+01:00) West Central Africa"
},
{
    tZCode : "Jordan Standard Time",
    tZDesc : "(GMT+02:00) Amman"
},
{
    tZCode : "GTB Standard Time",
    tZDesc : "(GMT+02:00) Athens, Bucharest, Istanbul"
},
{
    tZCode : "Middle East Standard Time",
    tZDesc : "(GMT+02:00) Beirut"
},
{
    tZCode : "Egypt Standard Time",
    tZDesc : "(GMT+02:00) Cairo"
},
{
    tZCode : "South Africa Standard Time",
    tZDesc : "(GMT+02:00) Harare, Pretoria"
},
{
    tZCode : "FLE Standard Time",
    tZDesc : "(GMT+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius"
},
{
    tZCode : "Israel Standard Time",
    tZDesc : "(GMT+02:00) Jerusalem"
},
{
    tZCode : "E. Europe Standard Time",
    tZDesc : "(GMT+02:00) Minsk"
},
{
    tZCode : "Namibia Standard Time",
    tZDesc : "(GMT+02:00) Windhoek"
},
{
    tZCode : "Arabic Standard Time",
    tZDesc : "(GMT+03:00) Baghdad"
},
{
    tZCode : "Arab Standard Time",
    tZDesc : "(GMT+03:00) Kuwait, Riyadh"
},
{
    tZCode : "Russian Standard Time",
    tZDesc : "(GMT+03:00) Moscow, St. Petersburg, Volgograd"
},
{
    tZCode : "E. Africa Standard Time",
    tZDesc : "(GMT+03:00) Nairobi"
},
{
    tZCode : "Georgian Standard Time",
    tZDesc : "(GMT+03:00) Tbilisi"
},
{
    tZCode : "Iran Standard Time",
    tZDesc : "(GMT+03:30) Tehran"
},
{
    tZCode : "Arabian Standard Time",
    tZDesc : "(GMT+04:00) Abu Dhabi, Muscat"
},
{
    tZCode : "Azerbaijan Standard Time",
    tZDesc : "(GMT+04:00) Baku"
},
{
    tZCode : "Mauritius Standard Time",
    tZDesc : "(GMT+04:00) Port Louis"
},
{
    tZCode : "Caucasus Standard Time",
    tZDesc : "(GMT+04:00) Yerevan"
},
{
    tZCode : "Afghanistan Standard Time",
    tZDesc : "(GMT+04:30) Kabul"
},
{
    tZCode : "Ekaterinburg Standard Time",
    tZDesc : "(GMT+05:00) Ekaterinburg"
},
{
    tZCode : "Pakistan Standard Time",
    tZDesc : "(GMT+05:00) Islamabad, Karachi"
},
{
    tZCode : "West Asia Standard Time",
    tZDesc : "(GMT+05:00) Tashkent"
},
{
    tZCode : "India Standard Time",
    tZDesc : "(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi"
},
{
    tZCode : "Sri Lanka Standard Time",
    tZDesc : "(GMT+05:30) Sri Jayawardenepura"
},
{
    tZCode : "Nepal Standard Time",
    tZDesc : "(GMT+05:45) Kathmandu"
},
{
    tZCode : "N. Central Asia Standard Time",
    tZDesc : "(GMT+06:00) Almaty, Novosibirsk"
},
{
    tZCode : "Central Asia Standard Time",
    tZDesc : "(GMT+06:00) Astana, Dhaka"
},
{
    tZCode : "Myanmar Standard Time",
    tZDesc : "(GMT+06:30) Yangon (Rangoon)"
},
{
    tZCode : "SE Asia Standard Time",
    tZDesc : "(GMT+07:00) Bangkok, Hanoi, Jakarta"
},
{
    tZCode : "North Asia Standard Time",
    tZDesc : "(GMT+07:00) Krasnoyarsk"
},
{
    tZCode : "China Standard Time",
    tZDesc : "(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi"
},
{
    tZCode : "North Asia East Standard Time",
    tZDesc : "(GMT+08:00) Irkutsk, Ulaan Bataar"
},
{
    tZCode : "Singapore Standard Time",
    tZDesc : "(GMT+08:00) Kuala Lumpur, Singapore"
},
{
    tZCode : "W. Australia Standard Time",
    tZDesc : "(GMT+08:00) Perth"
},
{
    tZCode : "Taipei Standard Time",
    tZDesc : "(GMT+08:00) Taipei"
},
{
    tZCode : "Tokyo Standard Time",
    tZDesc : "(GMT+09:00) Osaka, Sapporo, Tokyo"
},
{
    tZCode : "Korea Standard Time",
    tZDesc : "(GMT+09:00) Seoul"
},
{
    tZCode : "Yakutsk Standard Time",
    tZDesc : "(GMT+09:00) Yakutsk"
},
{
    tZCode : "Cen. Australia Standard Time",
    tZDesc : "(GMT+09:30) Adelaide"
},
{
    tZCode : "AUS Central Standard Time",
    tZDesc : "(GMT+09:30) Darwin"
},
{
    tZCode : "E. Australia Standard Time",
    tZDesc : "(GMT+10:00) Brisbane"
},
{
    tZCode : "AUS Eastern Standard Time",
    tZDesc : "(GMT+10:00) Canberra, Melbourne, Sydney"
},
{
    tZCode : "West Pacific Standard Time",
    tZDesc : "(GMT+10:00) Guam, Port Moresby"
},
{
    tZCode : "Tasmania Standard Time",
    tZDesc : "(GMT+10:00) Hobart"
},
{
    tZCode : "Vladivostok Standard Time",
    tZDesc : "(GMT+10:00) Vladivostok"
},
{
    tZCode : "Central Pacific Standard Time",
    tZDesc : "(GMT+11:00) Magadan, Solomon Is., New Caledonia"
},
{
    tZCode : "New Zealand Standard Time",
    tZDesc : "(GMT+12:00) Auckland, Wellington"
},
{
    tZCode : "Fiji Standard Time",
    tZDesc : "(GMT+12:00) Fiji, Kamchatka, Marshall Is."
},
{
    tZCode : "Tonga Standard Time",
    tZDesc : "(GMT+13:00) Nuku'alofa"
},
{
    tZCode : "Azores Standard Time",
    tZDesc : "(GMT-01:00) Azores"
},
{
    tZCode : "Cape Verde Standard Time",
    tZDesc : "(GMT-01:00) Cape Verde Is."
},
{
    tZCode : "Mid-Atlantic Standard Time",
    tZDesc : "(GMT-02:00) Mid-Atlantic"
},
{
    tZCode : "E. South America Standard Time",
    tZDesc : "(GMT-03:00) Brasilia"
},
{
    tZCode : "Argentina Standard Time",
    tZDesc : "(GMT-03:00) Buenos Aires"
},
{
    tZCode : "SA Eastern Standard Time",
    tZDesc : "(GMT-03:00) Georgetown"
},
{
    tZCode : "Greenland Standard Time",
    tZDesc : "(GMT-03:00) Greenland"
},
{
    tZCode : "Montevideo Standard Time",
    tZDesc : "(GMT-03:00) Montevideo"
},
{
    tZCode : "Newfoundland Standard Time",
    tZDesc : "(GMT-03:30) Newfoundland"
},
{
    tZCode : "Atlantic Standard Time",
    tZDesc : "(GMT-04:00) Atlantic Time (Canada)"
},
{
    tZCode : "SA Western Standard Time",
    tZDesc : "(GMT-04:00) La Paz"
},
{
    tZCode : "Central Brazilian Standard Time",
    tZDesc : "(GMT-04:00) Manaus"
},
{
    tZCode : "Pacific SA Standard Time",
    tZDesc : "(GMT-04:00) Santiago"
},
{
    tZCode : "Venezuela Standard Time",
    tZDesc : "(GMT-04:30) Caracas"
},
{
    tZCode : "SA Pacific Standard Time",
    tZDesc : "(GMT-05:00) Bogota, Lima, Quito, Rio Branco"
},
{
    tZCode : "Eastern Standard Time",
    tZDesc : "(GMT-05:00) Eastern Time (US & Canada)"
},
{
    tZCode : "US Eastern Standard Time",
    tZDesc : "(GMT-05:00) Indiana (East)"
},
{
    tZCode : "Central America Standard Time",
    tZDesc : "(GMT-06:00) Central America"
},
{
    tZCode : "Central Standard Time",
    tZDesc : "(GMT-06:00) Central Time (US & Canada)"
},
{
    tZCode : "Central Standard Time (Mexico)",
    tZDesc : "(GMT-06:00) Guadalajara, Mexico City, Monterrey"
},
{
    tZCode : "Canada Central Standard Time",
    tZDesc : "(GMT-06:00) Saskatchewan"
},
{
    tZCode : "US Mountain Standard Time",
    tZDesc : "(GMT-07:00) Arizona"
},
{
    tZCode : "Mountain Standard Time (Mexico)",
    tZDesc : "(GMT-07:00) Chihuahua, La Paz, Mazatlan"
},
{
    tZCode : "Mountain Standard Time",
    tZDesc : "(GMT-07:00) Mountain Time (US & Canada)"
},
{
    tZCode : "Pacific Standard Time",
    tZDesc : "(GMT-08:00) Pacific Time (US & Canada)"
},
{
    tZCode : "Pacific Standard Time (Mexico)",
    tZDesc : "(GMT-08:00) Tijuana, Baja California"
},
{
    tZCode : "Alaskan Standard Time",
    tZDesc : "(GMT-09:00) Alaska"
},
{
    tZCode : "Hawaiian Standard Time",
    tZDesc : "(GMT-10:00) Hawaii"
},
{
    tZCode : "Samoa Standard Time",
    tZDesc : "(GMT-11:00) Midway Island, Samoa"
},
{
    tZCode : "Dateline Standard Time",
    tZDesc : "(GMT-12:00) International Date Line West"
}


3

我怀疑这是大多数人想要的东西:

Microsoft时区索引值

希望MS即使在XP之后也能保持最新状态。


只是在此链接上的一条注释,无论出于何种原因,他们似乎发布的时区ID都有些许错误。例如,他们拥有美国,而不仅仅是美国
大卢克

3
有一个带有数字索引的列...有人知道我是否可以通过该索引获得时区,而不是依赖字符串名称吗?
Mike Ruhlin 2014年

您知道这些“时区索引” ID的用途是什么?它们仅适用于Windows XP和以前的版本吗?
汉普顿特里2015年



1
var timeZoneInfos = TimeZoneInfo.GetSystemTimeZones();

上面提供了时区列表,其中包括ID。


0
DateTime dt;
TimeZoneInfo tzf;
tzf = TimeZoneInfo.FindSystemTimeZoneById("TimeZone String");
dt = TimeZoneInfo.ConvertTime(DateTime.Now, tzf);
lbltime.Text = dt.ToString();

0

这是经过充分测试并为我工作的代码。您可以使用它,只需将其复制并粘贴到aspx页和cs页中。

这是我的博客,您可以在此处下载完整代码。谢谢。

http://www.c-sharpcorner.com/blogs/display-all-the-timezone-information-in-dropdown-list-of-a-local-system-using-c-sharp-with-asp-net

<form id="form1" runat="server">
    <div style="font-size: 30px; padding: 25px; text-align: center;">
        Get Current Date And Time Of All TimeZones
    </div>
    <hr />
    <div style="font-size: 18px; padding: 25px; text-align: center;">
        <div class="clsLeft">
            Select TimeZone :-
        </div>
        <div class="clsRight">
            <asp:DropDownList ID="ddlTimeZone" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlTimeZone_SelectedIndexChanged"
                Font-Size="18px">
            </asp:DropDownList>
        </div>
        <div class="clearspace">
        </div>
        <div class="clsLeft">
            Selected TimeZone :-
        </div>
        <div class="clsRight">
            <asp:Label ID="lblTimeZone" runat="server" Text="" />
        </div>
        <div class="clearspace">
        </div>
        <div class="clsLeft">
            Current Date And Time :-
        </div>
        <div class="clsRight">
            <asp:Label ID="lblCurrentDateTime" runat="server" Text="" />
        </div>
    </div>
    <p>
        &nbsp;</p>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    </form>

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindTimeZone();
            GetSelectedTimeZone();
        }
    }

    protected void ddlTimeZone_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetSelectedTimeZone();
    }

    /// <summary>
    /// Get all timezone from local system and bind it in dropdownlist
    /// </summary>
    private void BindTimeZone()
    {
        foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones())
        {
            ddlTimeZone.Items.Add(new ListItem(z.DisplayName, z.Id));
        }
    }

    /// <summary>
    /// Get selected timezone and current date & time
    /// </summary>
    private void GetSelectedTimeZone()
    {
        DateTimeOffset newTime = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(ddlTimeZone.SelectedValue));
        //DateTimeOffset newTime2 = TimeZoneInfo.ConvertTime(DateTimeOffset.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(ddlTimeZone.SelectedValue));
        lblTimeZone.Text = ddlTimeZone.SelectedItem.Text;
        lblCurrentDateTime.Text = newTime.ToString();
        string str;
        str = lblCurrentDateTime.Text;
        string s=str.Substring(0, 10);
        DateTime dt = new DateTime();
        dt = Convert.ToDateTime(s);
       // Response.Write(dt.ToString());
        Response.Write(ddlTimeZone.SelectedValue);

    }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.