September 2019
Intermediate to advanced
816 pages
18h 47m
English
Jumping to JDK 8, the focus is on LocalDate, LocalTime, LocalDateTime, Instant, and many more. The new Java date-time API comes with methods that are dedicated to adding or subtracting an amount of time. LocalDate, LocalTime, LocalDateTime, ZonedDateTime, OffsetDateTime, Instant, Period, Duration, and many others come with methods such as plusFoo() and minusFoo(), where Foo can be replaced with the unit of time (for example, plusYears(), plusMinutes(), minusHours(), minusSeconds(), and so on).
Let's assume the following LocalDateTime:
// 2019-02-25T14:55:06.651155500LocalDateTime ldt = LocalDateTime.now();
Adding 10 minutes is as easy as calling LocalDateTime.plusMinutes(long minutes), while subtracting 10 minutes ...