C# TimeZoneInfo IsDaylightSavingTime(DateTime)

Description

TimeZoneInfo IsDaylightSavingTime(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.

Syntax

TimeZoneInfo.IsDaylightSavingTime(DateTime) has the following syntax.


public bool IsDaylightSavingTime(
  DateTime dateTime
)

Parameters

TimeZoneInfo.IsDaylightSavingTime(DateTime) has the following parameters.

  • dateTime - A date and time value.

Returns

TimeZoneInfo.IsDaylightSavingTime(DateTime) method returns true if the dateTime parameter is a daylight saving time; otherwise, false.

Example


/*  w w w  .j a  va 2  s . c om*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    DateTime unclearDate = new DateTime(2014, 11, 4, 1, 30, 0);

    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 ");
  
    if (TimeZoneInfo.Local.IsAmbiguousTime(unclearDate) || 
        TimeZoneInfo.Local.IsDaylightSavingTime(unclearDate))
        Console.WriteLine("{0} may be daylight saving time in {1}.", 
                          unclearDate, TimeZoneInfo.Local.DisplayName);  

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version