3

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...

Community
  • 1
  • 1
Nestor
  • 13,706
  • 11
  • 78
  • 119
  • possible duplicate of [What is the System.TimeZoneInfo.IsDaylightSavingTime equivalent in NodaTime?](http://stackoverflow.com/questions/15211052/what-is-the-system-timezoneinfo-isdaylightsavingtime-equivalent-in-nodatime) – Matt Johnson-Pint Aug 03 '14 at 22:25

2 Answers2

5

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();
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

You can try this:

var localTimeZone = DateTimeZoneProviders.Tzdb.GetSystemDefault();
var now = SystemClock.Instance.Now;
var interval = localTimeZone.GetZoneInterval(now);
// inspect interval.Savings
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
  • Thanks. This did it: var isDLS = DateTimeZoneProviders.Tzdb.GetSystemDefault().GetZoneInterval(SystemClock.Instance.Now).Savings.Ticks!=0 – Nestor Jul 29 '14 at 09:44