C# FindTimeZoneById()
方法使用的时区ID列表
简介:
在 C# 中处理时区时,TimeZoneInfo
类提供了一种方便的方法来访问和操作时区信息。FindTimeZoneById()
方法允许您通过其标识符检索特定时区的 TimeZoneInfo
对象。但是,查找所有受支持时区标识符的完整列表可能具有挑战性。
访问时区ID列表:
要获取时区 ID 的完整列表,请使用 TimeZoneInfo
类的 GetSystemTimeZones()
方法。此方法返回一个 IEnumerable<TimeZoneInfo>
集合,其中包含操作系统支持的所有时区。
代码示例:
以下代码片段演示了如何使用 GetSystemTimeZones()
方法打印所有时区 ID 的列表:
<code class="language-csharp">using System; namespace TimeZoneIds { class Program { static void Main(string[] args) { foreach (TimeZoneInfo z in TimeZoneInfo.GetSystemTimeZones()) { Console.WriteLine(z.Id); } } } }</code>
结果:
在 Windows 7 工作站上运行时,上述代码输出以下时区 ID 列表:
<code>Dateline Standard Time UTC-11 Samoa Standard Time Hawaiian Standard Time Alaskan Standard Time Pacific Standard Time (Mexico) Pacific Standard Time US Mountain Standard Time Mountain Standard Time (Mexico) Mountain Standard Time Central America Standard Time Central Standard Time Central Standard Time (Mexico) Canada Central Standard Time SA Pacific Standard Time Eastern Standard Time US Eastern Standard Time Venezuela Standard Time Paraguay Standard Time Atlantic Standard Time Central Brazilian Standard Time SA Western Standard Time Pacific SA Standard Time Newfoundland Standard Time E. South America Standard Time Argentina Standard Time SA Eastern Standard Time Greenland Standard Time Montevideo Standard Time UTC-02 Mid-Atlantic Standard Time Azores Standard Time Cape Verde Standard Time Morocco Standard Time UTC GMT Standard Time Greenwich Standard Time W. Europe Standard Time Central Europe Standard Time Romance Standard Time Central European Standard Time W. Central Africa Standard Time Namibia Standard Time Jordan Standard Time GTB Standard Time Middle East Standard Time Egypt Standard Time Syria Standard Time South Africa Standard Time FLE Standard Time Israel Standard Time E. Europe Standard Time Arabic Standard Time Arab Standard Time Russian Standard Time E. Africa Standard Time Iran Standard Time Arabian Standard Time Azerbaijan Standard Time Mauritius Standard Time Georgian Standard Time Caucasus Standard Time Afghanistan Standard Time Ekaterinburg Standard Time Pakistan Standard Time West Asia Standard Time India Standard Time Sri Lanka Standard Time Nepal Standard Time Central Asia Standard Time Bangladesh Standard Time N. Central Asia Standard Time Myanmar Standard Time SE Asia Standard Time North Asia Standard Time China Standard Time North Asia East Standard Time Singapore Standard Time W. Australia Standard Time Taipei Standard Time Ulaanbaatar Standard Time Tokyo Standard Time Korea Standard Time Yakutsk Standard Time Cen. Australia Standard Time AUS Central Standard Time E. Australia Standard Time AUS Eastern Standard Time West Pacific Standard Time Tasmania Standard Time Vladivostok Standard Time Central Pacific Standard Time New Zealand Standard Time UTC+12 Fiji Standard Time Kamchatka Standard Time Tonga Standard Time</code>
附加说明:
支持的时区 ID 列表可能会因操作系统及其更新而异。为了确保访问最新的列表,请考虑使用维护完整时区标识符数据库的库或在线资源。
以上是如何获取与 C# 的'FindTimeZoneById()”一起使用的完整时区 ID 列表?的详细内容。更多信息请关注PHP中文网其他相关文章!