문제

How do I find out if my current local time is adjusted by Daylight Savings or not. Basically the equivalent of DateTime.Now.IsDaylightSavingTime() in NodaTime

I saw this, but could not make the translation to Noda...

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top