Ad

Does Java 8’s ZoneOffset Account For DST?

As I mentioned in title, does Java 8's ZoneOffset account for DST? Can I have different zone offsets in different summer/winter time?

Ad

Answer

No, a ZoneOffset is constant. To account for summer time (daylight saving time), you need a ZoneId, it accounts for DST and other changes in UTC offset. And will thus correspond to different ZoneOffsets in summer and winter if your time zone uses DST (far from all time zones do).

EDIT: ZoneOffset is a subclass of ZoneId, so you may say that a ZoneOffset is also a kind of ZoneId. But a special kind of ZoneId where the offset never changes. This inheritance relationship does not reflect the relationship between offsets and zones in real life, but has been made so because it is very often practical in programming.

Ad
source: stackoverflow.com
Ad