The DateTime.IsDaylightSavingTime() method in C# is used to indicate whether this instance of DateTime is within the daylight saving time range for the current time zone.
Syntax
Following is the syntax −
public bool IsDaylightSavingTime ();
Example
Let us now see an example to implement the DateTime.IsDaylightSavingTime() method −
using System;
public class Demo {
public static void Main() {
DateTime d = new DateTime(2019, 10, 11, 7, 10, 40);
bool res = d.IsDaylightSavingTime();
if (res)
Console.WriteLine("TRUE: This instance of DateTime is within the daylight saving time range for the current time zone.");
else
Console.WriteLine("FALSE: This instance of DateTime is within the daylight saving time range for the current time zone.");
}
}Output
This will produce the following output −
FALSE: This instance of DateTime is within the daylight saving time range for the current time zone.
Example
Let us now see another example to implement the DateTime.IsDaylightSavingTime() method −
using System;
public class Demo {
public static void Main() {
DateTime d = DateTime.Now;
bool res = d.IsDaylightSavingTime();
if (res)
Console.WriteLine("TRUE: This instance of DateTime is within the daylight saving time range for the current time zone.");
else
Console.WriteLine("FALSE: This instance of DateTime is within the daylight saving time range for the current time zone.");
}
}Output
This will produce the following output −
FALSE: This instance of DateTime is within the daylight saving time range for the current time zone.