TimeZoneInfo.Local 屬性

定義

取得代表本地時區的 TimeZoneInfo 物件。Gets a TimeZoneInfo object that represents the local time zone.

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

屬性值

代表本地時區的物件。An object that represents the local time zone.

屬性

範例

下列範例會抓取代表當地時區的 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.

備註

當地時區是執行程式碼所在電腦上的時區。The local time zone is the time zone on the computer where the code is executing.

重要

您應該一律透過 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.

適用於

另請參閱