September 2019
Intermediate to advanced
816 pages
18h 47m
English
The Period class is meant to represent an amount of time using date-based values (years, months, weeks, and days). This period of time can be obtained in different ways. For example, a period of 120 days can be obtained as follows:
Period fromDays = Period.ofDays(120); // P120D
Or, a period of 2,000 years, 11 months and 24 days can be obtained via the of() method, as follows:
Period periodFromUnits = Period.of(2000, 11, 24); // P2000Y11M24D
Period can also be obtained from LocalDate:
LocalDate localDate = LocalDate.now();Period periodFromLocalDate = Period.of(localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth()); ...