If you just want to know whether DST is supported by the local time zone, use:
bool hasDST = TimeZoneInfo.Local.SupportsDaylightSavingTime;
This will be false in either of these conditions:
If you specifically want to know if the user has disabled DST for a time zone that normally supports it, then do this:
bool actuallyHasDST = TimeZoneInfo.Local.SupportsDaylightSavingTime;
bool usuallyHasDST = TimeZoneInfo.FindSystemTimeZoneById(TimeZoneInfo.Local.Id)
.SupportsDaylightSavingTime;
bool dstDisabled = usuallyHasDST && !actuallyHasDST;
The dstDisabled
variable will be true only when the user has specifically cleared the "Automatically Adjust Clock for Daylight Saving Time" checkbox. If the box doesn't exist because the zone doesn't support DST to begin with, then dstDisabled
will be false.
How does this work?
Windows stores the chosen time zone settings in the registry at:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
The DynamicDaylightTimeDisabled
key is set to 1
when the box is cleared. Otherwise it is set to 0
.
One of the answers in the other question you mentioned specifically checked for this value, which is also an acceptable solution.
Calling TimeZoneInfo.Local
takes into account all of the information in that key.
Looking up the time zone by the Id
does not take into account any of the information in the registry, other than the Id
itself, which is stored in the TimeZoneKeyName
value.
By comparing the registry-created information against the looked-up information, you can determine whether DST has been disabled.
Note that this is also well described in the remarks section of the MSDN documentation for TimeZoneInfo.Local
.