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
Asked
Active
Viewed 3,947 times
4 Answers
8
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.");
}
-
What about using DateTime.IsDaylightSavingTime? – ABH Mar 30 '12 at 06:35
-
2@hamad: Gosh, I'd never even seen that. Personally I *wouldn't* use it, because a) it doesn't tell you whether the current time zone even supports DST; b) you're really asking a question which is logically about a time zone at a particular point in time - it's a lot more flexible to use the sort of code I've presented IMO; c) it doesn't use the ghastly "let's just use the system default time zone implicitly" aspect of `DateTime`. I'm not a fan of `DateTime`, for various reasons... – Jon Skeet Mar 30 '12 at 06:42
2
Here is another example in C#
private static bool IsDayLightSavingsEnabled()
{
try
{
var result = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "DynamicDaylightTimeDisabled", 1);
return !Convert.ToBoolean(result); //0 - Checked/enabled, 1 - Unchecked/disabled
}
catch
{ }
return false;
}

Rahbek
- 1,331
- 14
- 9
2
You can read the registry to determine if the checkbox is checked or not. Read this key,
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation DynamicDaylightTimeDisabled
= 0 or 1 (disabled)
So something like :
Dim retval As Object = Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "DynamicDaylightTimeDisabled", 0)
If retval IsNot Nothing Then
Select Case CInt(retval)
Case 0
Trace.WriteLine("Automatically adjust clock for Daylight Saving Time is checked")
Case 1
Trace.WriteLine("Automatically adjust clock for Daylight Saving Time is NOT checked")
End Select
End If
-
This tells if the check box is enabled, but does not tell if DST is currently in effect. – Moby Disk Aug 12 '14 at 20:40
-
perhaps that's what some of us want. I am running a report full of utc dates and if i did not know the state of that checkbox, and account for it, timezoneinfo will always convert based on it being checked. – John Lord May 20 '20 at 14:41