Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java8 - how to know if daylight savings is on now

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

like image 943
flo Avatar asked Sep 03 '14 07:09

flo


People also ask

How do you know if daylight savings is on or off?

Most of the United States begins Daylight Saving Time at 2:00 a.m. on the second Sunday in March and reverts to standard time on the first Sunday in November. In the U.S., each time zone switches at a different time. In the European Union, Summer Time begins and ends at 1:00 a.m. Universal Time (Greenwich Mean Time).

Is daylight savings time active now?

In the U.S., daylight saving time starts on the second Sunday in March and ends on the first Sunday in November, with the time changes taking place at 2:00 a.m. local time.

How do they determine when daylight savings time begins?

Starting in 2007, DST begins in the U.S. on the second Sunday in March, when people move their clocks forward an hour at 2 a.m. local standard time (so at 2 a.m. on that day, the clocks will then read 3 a.m. local daylight time).


1 Answers

ZoneRules contains the functionality you are intrested in:

public static boolean isDST(ZonedDateTime t) {
    return t.getZone().getRules().isDaylightSavings(t.toInstant());
}
like image 103
Joop Eggen Avatar answered Sep 30 '22 12:09

Joop Eggen