TimeZoneInfo.IsDaylightSavingTime メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定された日付と時刻が、現在の TimeZoneInfo オブジェクトのタイム ゾーンの夏時間の範囲内かどうかを示します。
オーバーロード
IsDaylightSavingTime(DateTimeOffset) |
指定された日付と時刻が、現在の TimeZoneInfo オブジェクトのタイム ゾーンの夏時間範囲内かどうかを示します。 |
IsDaylightSavingTime(DateTime) |
指定された日付と時刻が、現在の TimeZoneInfo オブジェクトのタイム ゾーンの夏時間範囲内かどうかを示します。 |
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 プロパティの値を取得します。
こちらもご覧ください
適用対象
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
。
例外
例
次の例では、このメソッド DisplayDateWithTimeZoneName
を使用して、タイム ゾーンの TimeZoneInfo.IsDaylightSavingTime 標準タイム名と夏時間名のどちらを表示するかを決定する名前のメソッドを定義します。
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.Local 、 DateTimeKind.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
無効な時刻が指定されている場合、メソッドの呼び出しは、パラメーターKindのプロパティのdateTime
値が の場合は DateTimeKind.Localan をスローArgumentExceptionします。それ以外の場合は、メソッドから返されますfalse
。
タイム ゾーン名を TimeZoneInfo.IsDaylightSavingTime 表示するときに、タイム ゾーンの StandardName 値またはその DaylightName 値を使用するかどうかを決定するメソッドを呼び出します。 図については、「例」セクションを参照してください。