共用方式為


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 系統中,它對應於登錄檔金鑰的 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones 子鍵。 在 Linux 和 macOS 上,它來自 ICU 函式庫。 它可以作為參數傳遞給方法, FindSystemTimeZoneById 實例 TimeZoneInfo 化代表特定時區的物件。

這很重要

雖然 Windows 登錄檔中的金鑰名稱最多可達 255 字元,但我們建議您為自訂時區指派的識別碼應為 32 字元或以下。 識別碼越長,取回時提供錯誤金鑰名稱的機率就越高。

Id 物業的價值通常(但不總是)與 StandardName 該物業的價值相同,但並非總是如此。 協調世界時區的識別碼為UTC。

適用於