title: Is the TimeUnit class broken?
body: <p>I noticed a strange behaviour of the TimeUnit class, so I created this minimal example to reproduce it.</p>
  
  <pre><code>long differenceInDays;
  
  Calendar c1 = Calendar.getInstance();
  Calendar c2 = Calendar.getInstance();
  
  c1.setTimeInMillis(1466062306000l); // Thu Jun 16 2016 09:31:46 GMT+0200
  c2.setTimeInMillis(1466028000000l); // Thu Jun 16 2016 00:00:00 GMT+0200
  
  differenceInDays = TimeUnit.DAYS.convert(c2.getTimeInMillis() - c1.getTimeInMillis(), TimeUnit.MILLISECONDS);
  System.out.println(differenceInDays); // obviously zero
  
  c2.add(Calendar.DATE, +1);
  differenceInDays = TimeUnit.DAYS.convert(c2.getTimeInMillis() - c1.getTimeInMillis(), TimeUnit.MILLISECONDS);
  System.out.println(differenceInDays); // why zero and not one?
  
  c2.add(Calendar.DATE, +1);
  differenceInDays = TimeUnit.DAYS.convert(c2.getTimeInMillis() - c1.getTimeInMillis(), TimeUnit.MILLISECONDS);
  System.out.println(differenceInDays); // suddenly a 1, but not a 2 like expected
  </code></pre>
  
  <p>It is obvious that the first time the difference is calculated it is 0, because not a whole day lies between the dates.</p>
  
  <p>But the second time a whole day is added, so how can the difference be still 0?</p>
  
  <p>Output:</p>
  
  <blockquote>
    <p>0<br>0<br>1</p>
  </blockquote>
  
  <p>I don't think this problem is daylight saving time or leap year related because I only do calculations within the same year, even month.</p>
  
  <p><a href="http://www.ruddwire.com/handy-code/date-to-millisecond-calculators/#.V2MbqvmLSUk" rel="nofollow">Here</a> is a date to milliseconds calculator for you to check.</p>