Search code examples
c#.netvb.nettimezonedst

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


Solution

  • 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.");
    }