Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if the DST is currently enabled

I need to find an easy way to know if the local machine's 'automatically adjust clock for Daylight Saving Time' option is enabled. If the option's on, I need to know whether it is currently applied (i.e. is it DST currently in the system). Thanks in advance

like image 583
Nissim Avatar asked Dec 09 '22 01:12

Nissim


2 Answers

You can find the current system default time zone and whether it is currently using DST (Daylight Saving Time) like this (.NET 3.5 onwards):

TimeZoneInfo zone = TimeZoneInfo.Local;
if (zone.SupportsDaylightSavingTime)
{
    Console.WriteLine("System default zone uses DST...");
    Console.WriteLine("In DST? {0}", zone.IsDaylightSavingTime(DateTime.UtcNow));       
}
else
{
    Console.WriteLine("System default zone does not use DST.");
}
like image 51
Jon Skeet Avatar answered Dec 11 '22 13:12

Jon Skeet


Another option may be is DateTime.IsDaylightSavingTime method. Check MSDN.

if (DateTime.Now.IsDaylightSavingTime())
    Console.WriteLine("Daylight Saving");
else
    Console.WriteLine("No Daylight Saving");
like image 31
ABH Avatar answered Dec 11 '22 13:12

ABH