TimeZoneInfo::IsDaylightSavingTime Method (DateTime)
Indicates whether a specified date and time falls in the range of daylight saving time for the time zone of the current TimeZoneInfo object.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- dateTime
-
Type:
System::DateTime
A date and time value.
Return Value
Type: System::Booleantrue if the dateTime parameter is a daylight saving time; otherwise, false.
| Exception | Condition |
|---|---|
| ArgumentException | The Kind property of the dateTime value is DateTimeKind::Local and dateTime is an invalid time. |
The return value of TimeZoneInfo::IsDaylightSavingTime is affected by the relationship between the time zone represented by the TimeZoneInfo object and the Kind property of the dateTime parameter, as the following table shows.
TimeZoneInfo object | DateTime.Kind property | Result |
|---|---|---|
DateTimeKind.Local | Determines whether dateTime is daylight saving time. | |
DateTimeKind.Utc | Converts dateTime from Coordinated Universal Time (UTC) to local time and determines whether it is daylight saving time. | |
DateTimeKind.Unspecified | Assumes that dateTime represents local time and determines whether it is daylight saving time. | |
DateTimeKind.Local, DateTimeKind.Unspecified, or DateTimeKind.Utc | Returns false (UTC does not support daylight saving time). | |
Any other TimeZoneInfoobject. | DateTimeKind.Local | Converts the local time to the equivalent time of the TimeZoneInfo object and then determines whether the latter is daylight saving time. |
Any other TimeZoneInfoobject. | DateTimeKind.Utc | Converts UTC to the equivalent time of the TimeZoneInfo object and then determines whether the latter is daylight saving time. |
Any other TimeZoneInfoobject. | DateTimeKind.Unspecified | Determines whether dateTime is daylight saving time. |
If the time zone represented by the TimeZoneInfo object does not support daylight saving time, the method always returns false. A number of time zones, including Utc, do not observe daylight saving time. To determine whether a time zone supports daylight saving time, retrieve the value of its SupportsDaylightSavingTime property.
If the dateTime parameter specifies an ambiguous time in the current object's time zone, the TimeZoneInfo::IsDaylightSavingTime method interprets dateTime as standard time and returns false if its Kind property is DateTimeKind::Local or DateTimeKind::Unspecified. If the Kind property is DateTimeKind::Utc, this method will select the correct ambiguous time and indicate whether it is a daylight saving time.
Because the TimeZoneInfo::IsDaylightSavingTime(DateTime) method can return false for a date and time that is ambiguous (that is, a date and time that can represent either a standard time or a daylight saving time in a particular time zone), the TimeZoneInfo::IsAmbiguousTime(DateTime) method can be paired with the IsDaylightSavingTime(DateTime) method to determine whether a time may be a daylight saving time. Because an ambiguous time is one that can be both a daylight saving time and a standard time, the IsAmbiguousTime(DateTime) method can be called first to determine whether a date and time may be a daylight saving time. If the method returns false, the IsDaylightSavingTime(DateTime) method can be called to determine whether the DateTime value is a daylight saving time. The following example illustrates this technique.
If the dateTime parameter specifies an invalid time, the method call throws an ArgumentException if the value of the dateTime parameter's Kind property is DateTimeKind::Local; otherwise, the method returns false.
Call the TimeZoneInfo::IsDaylightSavingTime method to determine whether to use a time zone's StandardName value or its DaylightName value when displaying the time zone name. See the Example section for an illustration.
Notes to Callers:
On Windows XP systems, this method applies only the current adjustment rule if the current instance is TimeZoneInfo::Local. As a result, the method may not accurately report whether dateTime is a daylight saving time for periods before the current adjustment rule came into effect. For more information, see the Notes for Callers section in the Local property.
The following example defines a method named DisplayDateWithTimeZoneName that uses the TimeZoneInfo::IsDaylightSavingTime method to determine whether to display a time zone's standard time name or daylight saving time name.
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1