How do I calculate difference in days between two dates?


In the following example we are going to calculate the differences between two dates. First, you’ll need to convert the date value into its corresponding value in milliseconds and then do the math calculation so we can get the difference in days, hours, minutes, etc.

For example to get the difference in day you’ll need to divide the difference in milliseconds with (24 * 60 * 60 * 1000).

Here is the result:

The better way to get number of days between two dates is to use the Joda Time API. In the following example you can see how to calculate date difference using Joda Time: How do I get number of days between two dates in Joda?.

Filed in: Java Util Package

Leave a Reply

Submit Comment

© 2014 Java Examples - Developed with