Interrogate a ZonedDateTime asking if in standard

2019-06-25 14:02发布

问题:

This question already has an answer here:

  • Java8 - how to know if daylight savings is on now 1 answer

How to ask a java.time.ZonedDateTime object if Daylight Saving Time (DST) applies to its moment or if standard time applies?

回答1:

@Jon's answer is good. Just want to mention there is ZoneRules#isDaylightSavings available.

ZonedDateTime zdt = ...;
ZoneRules rules = zdt.getZone().getRules();
boolean isDst = rules.isDaylightSavings(zdt.toInstant());

And possible duplicate question here.