-2

I have two dates String dateOne="ddMMyyyy" String dateTwo="ddMMyyyy"

I want the difference like 2years 3months 10days

How can i do that?

  • Duplicate of https://stackoverflow.com/questions/21285161/android-difference-between-two-dates. Modify the code to suite it to your needs. – Soumya Aug 30 '17 at 18:54
  • Possible duplicate of [Android difference between Two Dates](https://stackoverflow.com/questions/21285161/android-difference-between-two-dates) – Soumya Aug 30 '17 at 18:56

1 Answers1

0

If you parse those strings into LocalDate, you can use the following line of code:

ChronoUnit.DAYS.between(firstDate, secondDate)

You can also use this method using between() method:

public long getDaysCountBetweenDates(LocalDate dateBefore, LocalDate dateAfter) {
    return DAYS.between(firstDate, secondDate);
}
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193