2

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,260
  • 10
  • 75
  • 115
  • 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

4

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
  • 18,869
  • 22
  • 90
  • 106
Jon Skeet
  • 1,335,956
  • 823
  • 8,931
  • 9,049
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
  • 366,661
  • 96
  • 610
  • 798
  • Thanks. This did it: var isDLS = DateTimeZoneProviders.Tzdb.GetSystemDefault().GetZoneInterval(SystemClock.Instance.Now).Savings.Ticks!=0 – Nestor Jul 29 '14 at 09:44