Feres.o
Feres.o

Reputation: 283

getting Date months/ rest of days difference

is there a way to get these information from two dates:

  1. calculate month between dates ( month for me is a complete month)
  2. calculate rest of days between dates

here is my example:

start date:

01/01/2014

end date:

21/02/2014

i need a resualt like this : months:1 days:20

onother example:

start date:

15/01/2014

end date:

10/03/2014

i need a resualt like this : months:1 days:25

Upvotes: 1

Views: 144

Answers (1)

Ravindra Ranwala
Ravindra Ranwala

Reputation: 21124

Using Java8 Date/Time API you may do it like so,

LocalDate startDate = LocalDate.of(2014, 1, 1);
LocalDate endDate = LocalDate.of(2014, 2, 21);

Period period = startDate.until(endDate);
System.out.println("months: " + period.getMonths() + " days: " + period.getDays());

Upvotes: 3

Related Questions