TimeZoneInfo.Local 屬性

定義

取得代表本地時區的 TimeZoneInfo 物件。

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

屬性值

代表本地時區的物件。

屬性

範例

下列範例會 TimeZoneInfo 擷取代表當地時區的 物件,並輸出其顯示名稱、標準時間名稱和日光節約時間名稱。

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.
open System

let localZone = TimeZoneInfo.Local
printfn $"Local Time Zone ID: {localZone.Id}"
printfn $"   Display Name is: {localZone.DisplayName}."
printfn $"   Standard name is: {localZone.StandardName}."
printfn $"   Daylight saving name is: {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.

備註

當地時區是執行程式碼之電腦上的時區。

重要

您應該一律透過 屬性存取當地時區, TimeZoneInfo.Local 而不是將當地時區指派給 TimeZoneInfo 物件變數。 這可防止 TimeZoneInfo 物件變數因為呼叫 ClearCachedData 方法而失效。

在 Windows 系統上, TimeZoneInfo 屬性所傳 TimeZoneInfo.Local 回的物件會反映主控台日期和時間應用程式中 [自動調整日光節約時間的時鐘] 核取方塊的設定。 如果未核取此核取方塊,則本機時區的快取複本不會包含日光節約時間資訊。 這表示:

不過,如果使用 FindSystemTimeZoneById 方法擷取本機時區的參考,則這不是真。

屬性 Local 會對應至 CurrentTimeZone 類別的 TimeZone 屬性。

適用於

另請參閱