12
I have seen many questions and answers on this topic, but none addressed my particular problem. I extended the java Calendar class (standard--no third party libraries), and needed to find the difference in days between two arbitrary dates.
Method:
- Change the time of both dates to midnight.
- Convert the dates to milliseconds.
- Find the difference between the two dates.
- Divide the result by the number of milliseconds in a day (24 * 60 * 60 * 1000).
- The result should be the difference in days.
And it sometimes is, and it sometimes isn't. Even tests on the same date can be off by one. What's going on?