TimeZoneInfo.IsDaylightSavingTime メソッド

定義

指定された日付と時刻が、現在の TimeZoneInfo オブジェクトのタイム ゾーンの夏時間の範囲内かどうかを示します。

オーバーロード

IsDaylightSavingTime(DateTime)

指定された日付と時刻が、現在の TimeZoneInfo オブジェクトのタイム ゾーンの夏時間範囲内かどうかを示します。

IsDaylightSavingTime(DateTimeOffset)

指定された日付と時刻が、現在の TimeZoneInfo オブジェクトのタイム ゾーンの夏時間範囲内かどうかを示します。

IsDaylightSavingTime(DateTime)

指定された日付と時刻が、現在の TimeZoneInfo オブジェクトのタイム ゾーンの夏時間範囲内かどうかを示します。

public:
 bool IsDaylightSavingTime(DateTime dateTime);
public bool IsDaylightSavingTime (DateTime dateTime);
member this.IsDaylightSavingTime : DateTime -> bool
Public Function IsDaylightSavingTime (dateTime As DateTime) As Boolean

パラメーター

dateTime
DateTime

日付と時刻の値。

戻り値

dateTime パラメーターが夏時間の範囲内の場合は true。それ以外の場合は false

例外

dateTime 値の Kind プロパティは Local で、dateTime は無効な時刻です。

次の例では、 メソッドを使用TimeZoneInfo.IsDaylightSavingTimeして、タイム ゾーンの標準時名と夏時間名のどちらを表示するかを決定する という名前のメソッドDisplayDateWithTimeZoneNameを定義します。

private void DisplayDateWithTimeZoneName(DateTime date1, TimeZoneInfo timeZone)
{
   Console.WriteLine("The time is {0:t} on {0:d} {1}", 
                     date1, 
                     timeZone.IsDaylightSavingTime(date1) ?
                         timeZone.DaylightName : timeZone.StandardName);   
}
// The example displays output similar to the following:
//    The time is 1:00 AM on 4/2/2006 Pacific Standard Time
let displayDateWithTimeZoneName (date1: DateTime) (timeZone: TimeZoneInfo) =
    printfn $"The time is {date1:t} on {date1:d} {if timeZone.IsDaylightSavingTime date1 then timeZone.DaylightName else timeZone.StandardName}" 
// The example displays output similar to the following:
//    The time is 1:00 AM on 4/2/2006 Pacific Standard Time
Private Sub DisplayDateWithTimeZoneName(date1 As Date, timeZone As TimeZoneInfo)
   Console.WriteLine("The time is {0:t} on {0:d} {1}", _
                     date1, _
                     IIf(timeZone.IsDaylightSavingTime(date1), _
                         timezone.DaylightName, timezone.StandardName))   
End Sub
' The example displays output similar to the following:
'    The time is 1:00 AM on 4/2/2006 Pacific Standard Time

注釈

の戻り値は、次の TimeZoneInfo.IsDaylightSavingTime 表に示すように、 オブジェクトによって TimeZoneInfo 表されるタイム ゾーンと Kind パラメーターの プロパティの間の dateTime リレーションシップの影響を受けます。

TimeZoneInfo オブジェクト DateTime.Kind プロパティ 結果
TimeZoneInfo.Local DateTimeKind.Local が夏時間であるかどうかを dateTime 判断します。
TimeZoneInfo.Local DateTimeKind.Utc 協定世界時 (UTC) から現地時刻に変換 dateTime し、夏時間かどうかを判断します。
TimeZoneInfo.Local DateTimeKind.Unspecified dateTime ローカル時刻を表し、夏時間であるかどうかを判断することを前提としています。
TimeZoneInfo.Utc DateTimeKind.LocalDateTimeKind.Unspecified、または DateTimeKind.Utc 戻り値 false (UTC は夏時間をサポートしていません)。
その他の TimeZoneInfo オブジェクト。 DateTimeKind.Local ローカル時刻を オブジェクトの同等の時刻に TimeZoneInfo 変換し、後者が夏時間であるかどうかを判断します。
その他の TimeZoneInfo オブジェクト。 DateTimeKind.Utc UTC を オブジェクトの同等の時刻に TimeZoneInfo 変換し、後者が夏時間であるかどうかを判断します。
その他の TimeZoneInfo オブジェクト。 DateTimeKind.Unspecified が夏時間であるかどうかを dateTime 判断します。

オブジェクトで表されるタイム ゾーンが夏時間を TimeZoneInfo サポートしていない場合、メソッドは常に を返します false。 を含む Utc多くのタイム ゾーンでは、夏時間は観察されません。 タイム ゾーンが夏時間をサポートしているかどうかを判断するには、その SupportsDaylightSavingTime プロパティの値を取得します。

パラメーターが現在のdateTimeオブジェクトのタイム ゾーンであいまいな時刻を指定する場合、メソッドは標準時として解釈dateTimeし、TimeZoneInfo.IsDaylightSavingTimeそのKindプロパティが または DateTimeKind.Unspecifiedの場合は DateTimeKind.Local を返falseします。 プロパティが Kind の場合、 DateTimeKind.Utcこのメソッドは正しいあいまいな時刻を選択し、夏時間であるかどうかを示します。

TimeZoneInfo.IsDaylightSavingTime(DateTime)メソッドはあいまいな日付と時刻 (つまり、特定のタイム ゾーンの標準時または夏時間を表すことができる日付と時刻) TimeZoneInfo.IsAmbiguousTime(DateTime) に対して を返falseすことができるため、メソッドを メソッドとIsDaylightSavingTime(DateTime)ペアにして、時刻が夏時間であるかどうかを判断できます。 あいまいな時刻は夏時間と標準時の両方になる可能性があるため、 IsAmbiguousTime(DateTime) メソッドを最初に呼び出して、日付と時刻が夏時間であるかどうかを判断できます。 メソッドが を返す false場合は、 メソッドを IsDaylightSavingTime(DateTime) 呼び出して、値が DateTime 夏時間であるかどうかを判断できます。 次の例は、この手法を示しています。

DateTime unclearDate = new DateTime(2007, 11, 4, 1, 30, 0);
// Test if time is ambiguous.
Console.WriteLine("In the {0}, {1} is {2}ambiguous.", 
                  TimeZoneInfo.Local.DisplayName, 
                  unclearDate, 
                  TimeZoneInfo.Local.IsAmbiguousTime(unclearDate) ? "" : "not ");
// Test if time is DST.
Console.WriteLine("In the {0}, {1} is {2}daylight saving time.", 
                  TimeZoneInfo.Local.DisplayName, 
                  unclearDate, 
                  TimeZoneInfo.Local.IsDaylightSavingTime(unclearDate) ? "" : "not ");
Console.WriteLine();    
// Report time as DST if it is either ambiguous or DST.
if (TimeZoneInfo.Local.IsAmbiguousTime(unclearDate) || 
    TimeZoneInfo.Local.IsDaylightSavingTime(unclearDate))
    Console.WriteLine("{0} may be daylight saving time in {1}.", 
                      unclearDate, TimeZoneInfo.Local.DisplayName);  
// The example displays the following output:
//    In the (GMT-08:00) Pacific Time (US & Canada), 11/4/2007 1:30:00 AM is ambiguous.
//    In the (GMT-08:00) Pacific Time (US & Canada), 11/4/2007 1:30:00 AM is not daylight saving time.
//    
//    11/4/2007 1:30:00 AM may be daylight saving time in (GMT-08:00) Pacific Time (US & Canada).
let unclearDate = DateTime(2007, 11, 4, 1, 30, 0)
// Test if time is ambiguous.
printfn $"""In the {TimeZoneInfo.Local.DisplayName}, {unclearDate} is {if TimeZoneInfo.Local.IsAmbiguousTime unclearDate then "" else "not "}ambiguous."""
// Test if time is DST.
printfn $"""In the {TimeZoneInfo.Local.DisplayName}, {unclearDate} is {if TimeZoneInfo.Local.IsDaylightSavingTime unclearDate then "" else "not "}daylight saving time.
"""
// Report time as DST if it is either ambiguous or DST.
if TimeZoneInfo.Local.IsAmbiguousTime unclearDate || TimeZoneInfo.Local.IsDaylightSavingTime unclearDate then
    printfn $"{unclearDate} may be daylight saving time in {TimeZoneInfo.Local.DisplayName}."

// The example displays the following output:
//    In the (GMT-08:00) Pacific Time (US & Canada), 11/4/2007 1:30:00 AM is ambiguous.
//    In the (GMT-08:00) Pacific Time (US & Canada), 11/4/2007 1:30:00 AM is not daylight saving time.
//    
//    11/4/2007 1:30:00 AM may be daylight saving time in (GMT-08:00) Pacific Time (US & Canada).
Dim unclearDate As Date = #11/4/2007 1:30AM#
' Test if time is ambiguous.
Console.WriteLine("In the {0}, {1} is {2}ambiguous.", _ 
                  TimeZoneInfo.Local.DisplayName, _
                  unclearDate, _
                  IIf(TimeZoneInfo.Local.IsAmbiguousTime(unclearDate), "", "not "))
' Test if time is DST.
Console.WriteLine("In the {0}, {1} is {2}daylight saving time.", _ 
                  TimeZoneInfo.Local.DisplayName, _
                  unclearDate, _
                  IIf(TimeZoneInfo.Local.IsDaylightSavingTime(unclearDate), "", "not "))
Console.WriteLine()    
' Report time as DST if it is either ambiguous or DST.
If TimeZoneInfo.Local.IsAmbiguousTime(unclearDate) OrElse _ 
   TimeZoneInfo.Local.IsDaylightSavingTime(unclearDate) Then
    Console.WriteLine("{0} may be daylight saving time in {1}.", _ 
                      unclearDate, TimeZoneInfo.Local.DisplayName)                                           
End If
' The example displays the following output:
'    In the (GMT-08:00) Pacific Time (US & Canada), 11/4/2007 1:30:00 AM is ambiguous.
'    In the (GMT-08:00) Pacific Time (US & Canada), 11/4/2007 1:30:00 AM is not daylight saving time.
'    
'    11/4/2007 1:30:00 AM may be daylight saving time in (GMT-08:00) Pacific Time (US & Canada).

パラメーターにdateTime無効な時刻が指定されている場合、パラメーターの プロパティの値が の場合、メソッド呼dateTimeKindび出しは をArgumentExceptionスローします。それ以外の場合、メソッドは DateTimeKind.Localを返しますfalse

タイム ゾーン名を TimeZoneInfo.IsDaylightSavingTime 表示するときに、タイム ゾーンの StandardName 値またはその DaylightName 値を使用するかどうかを判断するには、 メソッドを呼び出します。 図については、「例」セクションを参照してください。

こちらもご覧ください

適用対象

IsDaylightSavingTime(DateTimeOffset)

指定された日付と時刻が、現在の TimeZoneInfo オブジェクトのタイム ゾーンの夏時間範囲内かどうかを示します。

public:
 bool IsDaylightSavingTime(DateTimeOffset dateTimeOffset);
public bool IsDaylightSavingTime (DateTimeOffset dateTimeOffset);
member this.IsDaylightSavingTime : DateTimeOffset -> bool
Public Function IsDaylightSavingTime (dateTimeOffset As DateTimeOffset) As Boolean

パラメーター

dateTimeOffset
DateTimeOffset

日付と時刻の値。

戻り値

dateTimeOffset パラメーターが夏時間の範囲内の場合は true。それ以外の場合は false

注釈

TimeZoneInfo.IsDaylightSavingTime 戻り値は、 オブジェクトによって表される TimeZoneInfo タイム ゾーンと Offset パラメーターの プロパティの間のリレーションシップの影響を dateTimeOffset 受けます。 が世界協定時刻 (UTC) からの現在のタイム ゾーンのオフセットに対応しない場合 dateTimeOffset 、メソッドはその時刻を現在のタイム ゾーンの時刻に変換します。 次に、その日付と時刻が夏時間であるかどうかを判断します。

オブジェクトで表されるタイム ゾーンが夏時間を TimeZoneInfo サポートしていない場合、メソッドは常に を返します false。 タイム ゾーンが夏時間をサポートしているかどうかを判断するには、その SupportsDaylightSavingTime プロパティの値を取得します。

こちらもご覧ください

適用対象