9

I need to find out whether daylight savings is on now using the new Java 8 datetime classes. I found an entry how to do this in jodatime:

jodatime how to know if daylight savings is on

But how can I find it out in Java 8? (jodatime should be kinda similar but I could not find the corresponding method java.time.ZonedDateTime.isStandardOffset())

Thanks for your help

Community
  • 1
  • 1
flo
  • 93
  • 1
  • 3
  • Why do you need to know the timezone? - Do you really need to know? Before you continue to write your code I would suggest watching https://www.youtube.com/watch?v=-5wpm-gesOY&index=61&list=UU9-y-6csu5WGm29I7JiwpnA – Robert3452 Sep 03 '14 at 09:09

1 Answers1

12

ZoneRules contains the functionality you are intrested in:

public static boolean isDST(ZonedDateTime t) {
    return t.getZone().getRules().isDaylightSavings(t.toInstant());
}
SpaceTrucker
  • 13,377
  • 6
  • 60
  • 99
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138