Check if a date and time(DateTime) is daylight saving time for time zone of TimeZoneInfo in CSharp

Description

The following code shows how to check if a date and time(DateTime) is daylight saving time for time zone of TimeZoneInfo.

Example


/*from  www.  j  a  v a  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 »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var