Reputation: 610
How can I obtain the Period
between two different LocalDate
instances using Java.
I googled, not able to find it.
Upvotes: 0
Views: 86
Reputation: 21124
A Period
is the amount of time between two LocalDate
. Same concept as Duration
. Here's the difference between the two: A Duration
measures an amount of time using time-based values (seconds, nanoseconds). A Period
uses date-based values (years, months, days). However, using Period
you can't get the hours, mins as you mentioned in the problem statement above.
Upvotes: 0
Reputation: 610
Yes, I got it.
LocalDate firstDate = LocalDate.of(2010, 5, 17); // 2010-05-17
LocalDate secondDate = LocalDate.of(2015, 3, 7); // 2015-03-07
Period period = Period.between(firstDate, secondDate);
System.out.println(period); //P4Y9M18D
Upvotes: 1