TimeZoneInfo.IsDaylightSavingTime 메서드

정의

지정된 날짜 및 시간이 현재 TimeZoneInfo 개체의 표준 시간대에 대한 일광 절약 시간 범위에 속하는지 여부를 나타냅니다.

오버로드

IsDaylightSavingTime(DateTime)

지정된 날짜 및 시간이 현재 TimeZoneInfo 개체의 표준 시간대에 대한 일광 절약 시간 범위에 속하는지 여부를 나타냅니다.

IsDaylightSavingTime(DateTimeOffset)

지정된 날짜 및 시간이 현재 TimeZoneInfo 개체의 표준 시간대에 대한 일광 절약 시간 범위에 속하는지 여부를 나타냅니다.

IsDaylightSavingTime(DateTime)

Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs

지정된 날짜 및 시간이 현재 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 dateTime UTC(협정 세계시)에서 현지 시간으로 변환하고 일광 절약 시간제인지 여부를 결정합니다.
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 현재 개체의 표준 시간대에서 모호한 시간을 지정하는 경우 메서드는 TimeZoneInfo.IsDaylightSavingTime 표준 시간으로 해석 dateTime 되고 해당 속성이 DateTimeKind.Local 또는 DateTimeKind.Unspecified인 경우 를 Kind 반환 false 합니다. 속성이 DateTimeKind.UtcKind 경우 이 메서드는 올바른 모호한 시간을 선택하고 일광 절약 시간인지 여부를 나타냅니다.

메서드는 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 잘못된 시간을 지정하면 메서드 호출은 매개 변수 KinddateTime 속성 DateTimeKind.Local값이 이면 을 throw하고ArgumentException, 그렇지 않으면 메서드는 를 반환합니다false.

메서드를 TimeZoneInfo.IsDaylightSavingTime 호출하여 표준 시간대 이름을 표시할 때 표준 시간대 값 StandardName 또는 해당 DaylightName 값을 사용할지 여부를 결정합니다. 일러스트레이션은 예제 섹션을 참조하세요.

추가 정보

적용 대상

IsDaylightSavingTime(DateTimeOffset)

Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs
Source:
TimeZoneInfo.cs

지정된 날짜 및 시간이 현재 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 .

추가 정보

적용 대상