This method calculates the amount in provided unit between this local date and the provided local date
package com.logicbig.example.localdate;
import java.time.LocalDate;
import java.time.Period;
public class UntilExample {
public static void main (String... args) {
LocalDate d1 = LocalDate.of(1999, 1, 20);
LocalDate d2 = LocalDate.of(2016, 12, 15);
Period p = d1.until(d2);
System.out.println(p);
System.out.printf("Years: %s, Months: %s, Days: %s%n",
p.getYears(), p.getMonths(), p.getDays());
//alternatively
Period p2 = Period.between(d1, d2);
System.out.println(p2);
}
}
Output
P17Y10M25D
Years: 17, Months: 10, Days: 25
P17Y10M25D