共用方式為


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 的性質。

適用於

另請參閱