TimeZoneInfo.Id 属性

定义

获取时区标识符。Gets the time zone identifier.

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

属性值

String

时区标识符。The time zone identifier.

示例

下面的示例列出了在本地计算机上定义的每个时区的标识符。The following example lists the identifier of each of the time zones defined on the local computer.

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);
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

注解

时区标识符是唯一标识特定时区的密钥字符串。The time zone identifier is a key string that uniquely identifies a particular time zone. 在 Windows 系统上,它对应于 Windows 系统上的注册表的 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zone 分支以及 Linux 和 macOS 上的 ICU 库 中的子项。On Windows systems, it corresponds to the subkeys of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zone branch of the registry on Windows systems and from the ICU Library on Linux and macOS. 它可以作为参数传递给 FindSystemTimeZoneById 方法,以实例化 TimeZoneInfo 表示特定时区的对象。It can be passed as a parameter to the FindSystemTimeZoneById method to instantiate a TimeZoneInfo object that represents a particular time zone.

重要

尽管 Windows 注册表中的密钥名称最多可以有255个字符,但我们建议你分配给自定义时区的标识符为32个字符或更少。Although a key name in the Windows registry can be a maximum of 255 characters, we recommend that an identifier that you assign to a custom time zone be 32 characters or fewer. 标识符越长,检索时提供错误键名称的可能性就越大。The longer the identifier, the greater the probability that an incorrect key name will be supplied when retrieving it.

属性的值 Id 通常(但不总是)与属性的值相同 StandardNameThe value of the Id property is usually, but not always, identical to that of the StandardName property. 协调世界时区的标识符是 UTC。The identifier of the Coordinated Universal Time zone is UTC.

适用于