Is DST enabled?

In Windows 7 "Time Zone Settings" you can enable or disable "Automatic Clock Adjustment for Daylight Saving Time". If this is disabled, then the PC clock will always show standard time, even if the time zone is set to a time zone that follows daylight saving time.

This question asks if DST is enabled, but the answer only says that the current date / time is within daylight saving time rules, so it should be adjusted, but the OS settings say to keep the time in the standard timezone.

How to get "Automatically adjust clock for daylight saving time" from C #

+3


source to share


1 answer


If you just want to know if DST is supported by the local timezone use:

bool hasDST = TimeZoneInfo.Local.SupportsDaylightSavingTime;

      

It will be false under any of these conditions:

  • The selected time zone does not use DST (e.g. Arizona and Hawaii)

  • The selected time zone uses DST, but the user has cleared the Automatically adjust clock for daylight saving time check box.

If you specifically want to know if a user has disabled DST for a time zone that normally supports it, follow these steps:



bool actuallyHasDST = TimeZoneInfo.Local.SupportsDaylightSavingTime;
bool usuallyHasDST = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneInfo.Local.Id)
                                 .SupportsDaylightSavingTime;
bool dstDisabled = usuallyHasDST && !actuallyHasDST;

      

The variable dstDisabled

will only be valid when the user specifically clears the Automatically adjust clock for daylight saving time check box. If the box does not exist because the zone does not support DST to begin with, then it dstDisabled

will be false.

How it works?

  • Windows stores the selected time zone settings in the registry at:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
    
          

  • The key is DynamicDaylightTimeDisabled

    set to 1

    when the field is cleared. Otherwise, it is set to 0

    .

    One of the answers in another question you mentioned specifically checked for this value, which is also an acceptable solution.

  • The call TimeZoneInfo.Local

    takes into account all the information in this key.

  • Finding the time zone using Id

    does not take into account any information in the registry other than the Id

    one that is stored in the value TimeZoneKeyName

    .

  • By comparing the information generated by the registry with the search information, you can determine if DST is disabled.

Note that this is also well described in the notes section of the MSDN documentation forTimeZoneInfo.Local

.

+3


source







All Articles