If you want to add a library that handles dates better than standard Java libraries, you can check out Joda .
Using Joda, you can calculate the difference between days:
Days d = Days.daysBetween(startDate, endDate); int days = d.getDays();
where startDate and endDate are versions of Joda, DateTime dates (actually the superclass of this).
Converting Java Date objects to Joda DateTime objects can be done by calling the constructor:
DateTime dateTime = new DateTime(javaDate);
Adding this library may be redundant for this particular problem, but if you are dealing with date and time processing, the library is definitely worth it.
source share