September 2019
Intermediate to advanced
816 pages
18h 47m
English
Starting with JDK 8, the recommended way to represent date-time information is via Temporal (for example, DateTime, DateLocalTime, ZonedDateTime, and so on).
Let's assume the following two LocalDate objects, January 1, 2018, and March 1, 2019:
LocalDate ld1 = LocalDate.of(2018, 1, 1);LocalDate ld2 = LocalDate.of(2019, 3, 1);
The simplest way to compute the difference between these two Temporal objects is via the ChronoUnit class. Beside representing the standard set of date periods units, ChronoUnit comes with several handy methods, including between(Temporal t1Inclusive, Temporal t2Exclusive). As its name suggests, the between() method calculates the amount of time between two Temporal objects. Let's see it at work to ...