TimeZoneInfo.Local Property

Definition

获取表示本地时区的 TimeZoneInfo 对象。Gets a TimeZoneInfo object that represents the local time zone.

public:
 static property TimeZoneInfo ^ Local { TimeZoneInfo ^ get(); };
public static TimeZoneInfo Local { get; }
[get: System.Security.SecurityCritical]
public static TimeZoneInfo Local { get; }
member this.Local : TimeZoneInfo
Public Shared ReadOnly Property Local As TimeZoneInfo

Property Value

TimeZoneInfo

一个对象,表示本地时区。An object that represents the local time zone.

Attributes

Examples

下面的示例检索一个表示本地时区的 TimeZoneInfo 对象,并输出其显示名称、标准时间名称和夏时制名称。The following example retrieves a TimeZoneInfo object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name.

using System;

public class Example
{
   public static void Main()
   {
      TimeZoneInfo localZone = TimeZoneInfo.Local;
      Console.WriteLine("Local Time Zone ID: {0}", localZone.Id);
      Console.WriteLine("   Display Name is: {0}.", localZone.DisplayName);
      Console.WriteLine("   Standard name is: {0}.", localZone.StandardName);
      Console.WriteLine("   Daylight saving name is: {0}.", localZone.DaylightName); 
   }
}
// The example displays output like the following:
//     Local Time Zone ID: Pacific Standard Time
//        Display Name is: (UTC-08:00) Pacific Time (US & Canada).
//        Standard name is: Pacific Standard Time.
//        Daylight saving name is: Pacific Daylight Time.
Module Example
   Public Sub Main()
      Dim localZone As TimeZoneInfo = TimeZoneInfo.Local
      Console.WriteLine("Local Time Zone ID: {0}", localZone.Id)
      Console.WriteLine("   Display Name is: {0}.", localZone.DisplayName)
      Console.WriteLine("   Standard name is: {0}.", localZone.StandardName)
      Console.WriteLine("   Daylight saving name is: {0}.", localZone.DaylightName) 
   End Sub
End Module
' The example displays output like the following:
'     Local Time Zone ID: Pacific Standard Time
'        Display Name is: (UTC-08:00) Pacific Time (US & Canada).
'        Standard name is: Pacific Standard Time.
'        Daylight saving name is: Pacific Daylight Time.

Remarks

本地时区是运行代码的计算机上的时区。The local time zone is the time zone on the computer where the code is executing.

Important

应始终通过 TimeZoneInfo.Local 属性访问本地时区,而不是将本地时区分配给 TimeZoneInfo 对象变量。You should always access the local time zone through the TimeZoneInfo.Local property rather than assigning the local time zone to a TimeZoneInfo object variable. 这会阻止 TimeZoneInfo 对象变量通过调用 ClearCachedData 方法来使其失效。This prevents the TimeZoneInfo object variable from being invalidated by a call to the ClearCachedData method.

在 Windows 系统中,TimeZoneInfo.Local 属性返回的 TimeZoneInfo 对象反映了控制面板日期和时间应用程序中 "自动调整夏令时时钟" 复选框的设置。On Windows systems, the TimeZoneInfo object returned by the TimeZoneInfo.Local property reflects the setting of the Automatically adjust clock for Daylight Saving Time checkbox in the Control Panel Date and Time application. 如果未选中该复选框,则本地时区的缓存副本不包含夏令时信息。If the checkbox is unchecked, the cached copy of the local time zone contains no daylight saving time information. 这意味着:This means that:

不过,如果使用 FindSystemTimeZoneById 方法检索对本地时区的引用,则不是这样。This is not true, however, if a reference to the local time zone is retrieved using the FindSystemTimeZoneById method.

Local 属性对应于 TimeZone 类的 CurrentTimeZone 属性。The Local property corresponds to the CurrentTimeZone property of the TimeZone class.

Applies to

See also