次の方法で共有


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.

注釈

ローカル タイム ゾーンは、コードが実行されているコンピューター上のタイム ゾーンです。

Important

ローカル タイム ゾーンを TimeZoneInfo オブジェクト変数に割り当てるのではなく、TimeZoneInfo.Local プロパティを使用してローカル タイム ゾーンに常にアクセスする必要があります。 これにより、 TimeZoneInfo オブジェクト変数は、 ClearCachedData メソッドの呼び出しによって無効になります。

Windows システムでは、TimeZoneInfo.Local プロパティによって返されるTimeZoneInfo オブジェクトは、コントロール パネルの日付と時刻アプリケーションの夏時間の自動調整の時計のチェック ボックスの設定を反映します。 チェック ボックスをオフにすると、ローカル タイム ゾーンのキャッシュされたコピーに夏時間情報が含まれます。 これは、次のことを意味します。

  • ローカル タイム ゾーンの GetAdjustmentRules メソッドは、長さが 0 の配列を返します。

  • ローカル タイム ゾーンの SupportsDaylightSavingTime プロパティは、 falseを返します。

  • ローカル タイム ゾーンには、あいまいまたは無効な時刻がありません ( IsAmbiguousTime へのすべての呼び出しまたは IsInvalidTime 戻り false)。

  • 個々のローカル時刻で IsDaylightSavingTime するすべての呼び出しは false を返します。

ただし、 FindSystemTimeZoneById メソッドを使用してローカル タイム ゾーンへの参照を取得する場合は、これは当てはまりません。

Local プロパティは、TimeZone クラスのCurrentTimeZone プロパティに対応します。

適用対象

こちらもご覧ください