Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do java.time API determines zone rules changes by the government?

I don't live in a country using DST.

  1. I save a future LocalDateTime, Offset from UTC and ZoneId in DB
  2. Government of that zone changes DST rules
  3. That future time comes, I will retrieve the LocalDateTime in that zone

If I apply ZoneId and Offset to get the LocalDateTime in that zone, how does java.time API get this correctly? How does it know that the government changes the rules? Does it fetch update from the internet?

like image 675
letthefireflieslive Avatar asked Sep 01 '17 02:09

letthefireflieslive


People also ask

Which API do you use to retrieve the time zone ID if you are given a time zone ID?

getId. Gets the unique time-zone ID.

What is difference between OffsetDateTime and ZonedDateTime?

ZonedDateTime handles a date and time with a corresponding time zone with a time zone offset from Greenwich/UTC. OffsetDateTime handles a date and time with a corresponding time zone offset from Greenwich/UTC, without a time zone ID.

What is a ZonedDateTime in the Java 8 date and time API?

ZonedDateTime is an immutable representation of a date-time with a time-zone. This class stores all date and time fields, to a precision of nanoseconds, and a time-zone, with a zone offset used to handle ambiguous local date-times.

What is the ZoneId for GMT?

What is the ZoneId for GMT? The ZoneId class is used to identify a time zone and provide the conversion rules between LocalDateTime and Instant. In terms of offset rules, ZoneId is divided into 2 types: ZoneId with a fixed time zone offset, such as "UTC+07", "GMT-05:40", "UT-03", "+05:50".


1 Answers

Timezone updates usually come with JRE updates. Whenever the timezone of some particular territory is changed, this information is included into the next version of JRE.

Here you can find some information on the timezone data for JRE/JDK.

If updating JRE/JDK is not an option, TZUpdater tool can be used to update only the timezone data without updating JRE/JDK.

All Java date/time APIs that support timezones implicitly use JRE's timezone data, so the only thing you need to worry about is keeping the timezone data in JRE up-to-date.

like image 181
Aleksei Budiak Avatar answered Nov 14 '22 23:11

Aleksei Budiak