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中文網其他相關文章!