0

Hi I need to calculate the difference between two dates and output can be one of these -- days or months or years and the output calculates all part so it can be in fraction also.

e.g:

24.03.15-14.04.15 (in days)=-21

24.03.15-14.04.15 (in months)=-0.75

24.03.15-14.04.15 (in years)=-1/12

Not able to calculate this.

Please explain it.

jh314
  • 27,144
  • 16
  • 62
  • 82
sky
  • 93
  • 2
  • 3
  • 15
  • possible duplicate of [How to calculate time difference in java?](http://stackoverflow.com/questions/4927856/how-to-calculate-time-difference-in-java) – halloei Mar 25 '15 at 14:31
  • This is not duplicate. its totally different. – sky Mar 25 '15 at 16:02
  • Have a look at [@Fizer Khan's answer](http://stackoverflow.com/a/20811441/3318377). Isn't it what you need? – halloei Mar 25 '15 at 16:24
  • possible duplicate of [Calculating the Difference Between Two Java Date Instances](http://stackoverflow.com/questions/1555262/calculating-the-difference-between-two-java-date-instances) – Basil Bourque Mar 25 '15 at 23:13

1 Answers1

0

Use Joda:

LocalDate d1 = new LocalDate(2015, 3, 15);
LocalDate d2 = new LocalDate(2015, 4, 14);
int days = Days.daysBetween(d1, d2).getDays();
Jean Logeart
  • 52,687
  • 11
  • 83
  • 118
  • confusion, is it includes all parts- years,months in it. like- 24.03.2011-14.06.2014 = should be total no. of days differences if needs day only – sky Mar 25 '15 at 15:47