TimeZoneInfo.Id 屬性

定義

取得時區識別項。

public:
 property System::String ^ Id { System::String ^ get(); };
public string Id { get; }
member this.Id : string
Public ReadOnly Property Id As String

屬性值

時區識別項。

範例

下列範例會列出本機電腦上定義之每個時區的識別碼。

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);
let zones = TimeZoneInfo.GetSystemTimeZones()
printfn $"The local system has the following {zones.Count} time zones"
for zone in zones do
    printfn $"{zone.Id}"
Dim zones As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
Console.WriteLine("The local system has the following {0} time zones", zones.Count)
For Each zone As TimeZoneInfo In zones
   Console.WriteLine(zone.Id)
Next

備註

時區識別碼是可唯一識別特定時區的索引鍵字串。 在 Windows 系統上,它會對應至 Windows 系統上登錄之 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zone 分支的子機碼,以及從 Linux 和 macOS 上的 ICU 程式庫 。 它可以當做參數傳遞至 FindSystemTimeZoneById 方法,以具現化 TimeZoneInfo 代表特定時區的 物件。

重要

雖然 Windows 登錄中的機碼名稱最多可以有 255 個字元,但我們建議您指派給自訂時區的識別碼為 32 個字元或更少。 識別碼越長,擷取時會提供不正確索引鍵名稱的機率就越大。

屬性的值 Id 通常與 屬性的值 StandardName 相同,但不一定相同。 國際標準時區的識別碼是 UTC。

適用於