Noda: Find out if in daylight saving
-
20-12-2019 - |
المحلول
Lasse's answer is correct, but it can be made simpler:
From v1.3 you can use ZonedDateTime.IsDaylightSavingTime
:
var zone = ...;
var now = ..;
var daylight = now.InZone(zone).IsDaylightSavingTime();
And from v2.0 (unreleased at the time of writing) you can use ZonedClock
to make the original conversion even simpler:
var now = zonedClock.GetCurrentZonedDateTime();
var daylight = now.IsDaylightSavingTime();
نصائح أخرى
You can try this:
var localTimeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
var now = SystemClock.Instance.Now;
var interval = localTimeZone.GetZoneInterval(now);
// inspect interval.Savings
لا تنتمي إلى StackOverflow