June 2018
Beginner
722 pages
18h 47m
English
The classes java.time.Period and java.time.Duration are designed to contain an amount of time:
The following code demonstrates their creation and use with the class LocalDateTime, but the same methods exist in the classes LocalDate (for Period) and LocalTime (for Duration):
LocalDateTime ldt1 = LocalDateTime.parse("2020-02-23T20:23:12");LocalDateTime ldt2 = ldt1.plus(Period.ofYears(2));System.out.println(ldt2); //prints: 2022-02-23T20:23:12//The following methods work the same way:ldt.minus(Period.ofYears(2));ldt.plus(Period.ofMonths(2));ldt.minus(Period. ...Read now
Unlock full access