Home »
.Net »
C# programs
C# - TimeZoneInfo.IsDaylightSavingTime() Method with Example
In this tutorial, we will learn about the C# TimeZoneInfo.IsDaylightSavingTime() method with its definition, usage, syntax, and example.
By Nidhi Last updated : March 31, 2023
TimeZoneInfo.IsDaylightSavingTime() Method
The TimeZoneInfo.IsDaylightSavingTime() is used to check whether a given date and time falls in the range of daylight saving time for the current TimeZoneInfo object's time zone.
Syntax
bool TimeZoneInfo. IsDaylightSavingTime (DateTime date_time);
Parameter(s)
- date_time: A date and time.
Return Value
This method returns a boolean value if the given date-time is daylight saving time then it returns true otherwise it returns false.
Exception(s)
C# Example of TimeZoneInfo.IsDaylightSavingTime() Method
The source code to determine given date and time is daylight saving time or not is given below. The given program is compiled and executed successfully.
using System;
using System.Globalization;
using System.Collections.ObjectModel;
class TimeZoneInfoDemo {
//Entry point of Program
static public void Main() {
DateTime dateTime1;
TimeZoneInfo time_zone = TimeZoneInfo.Local;
dateTime1 = new DateTime(2020, 2, 10, 10, 10, 10);
if (time_zone.IsDaylightSavingTime(dateTime1))
Console.WriteLine("It is daylight saving time");
else
Console.WriteLine("It is not daylight saving time");
}
}
Output
It is not daylight saving time
Press any key to continue . . .
C# TimeZoneInfo Class Programs »