Home »
.Net »
C# programs
C# program to determine given date and time is daylight saving time or not (TimeZoneInfo.IsDaylightSavingTime() Method)
C# TimeZoneInfo.IsDaylightSavingTime() Method: Here, we are going to learn how to determine given date and time is daylight saving time or not in C#.Net?
Submitted by Nidhi, on May 20, 2021
The IsDaylightSavingTime() method of TimeZoneInfo class 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):
Program:
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 »