title: Java Calendar: Getting Difference Between Two Dates/Times - Off by One
body: <p>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 <strong>days</strong> between two arbitrary dates.</p>
  
  <p>Method:</p>
  
  <ol>
  <li>Change the time of both dates to midnight.</li>
  <li>Convert the dates to milliseconds.</li>
  <li>Find the difference between the two dates.</li>
  <li>Divide the result by the number of milliseconds in a day (24 * 60 *
  60 * 1000).</li>
  <li>The result should be the difference in days.</li>
  </ol>
  
  <p>And it sometimes is, and it sometimes isn't.  Even tests on the same date can be off by one. What's going on?</p>