title: Calendar method getTimeInMillis() returning wrong value
body: <p>I have a validation method which will take two input as start date and end date and check whether end date is valid i.e. after start date.
  I used Calendar method <code>getTimeInMillis()</code> to get milliseconds of two dates and get the difference. If the difference is negative then its invalid end date i.e. end date is before start date.
  The millisecond value of end date should be always greater that start date. But in some cases <code>getTimeInMillis()</code> giving greater value in case of start date.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class ValidationProcessor {
      private void testTimeDiff(String startDate, String endDate) throws Exception {
          Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
          Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
          // Set the dates for calendars
          cal1.set(Integer.parseInt(startDate.split("-")[0]), Integer.parseInt(startDate.split("-")[1]),
              Integer.parseInt(startDate.split("-")[2]));
          cal2.set(Integer.parseInt(endDate.split("-")[0]), Integer.parseInt(endDate.split("-")[1]),
              Integer.parseInt(endDate.split("-")[2]));
          long milis1 = cal1.getTimeInMillis();
          long milis2 = cal2.getTimeInMillis();
          System.out.println("milis1::: " + milis1);
          System.out.println("milis2::: " + milis2);
          long diff = milis2 - milis1;
          System.out.println("diff::: " + diff);
          if (diff &lt;= 0) {
              throw new Exception("Invalid End Date. End Date Must Be After Start Date");
          }
      }
  
      public static void main(String args[]) {
          ValidationProcessor test = new ValidationProcessor();
          try {
              test.testTimeDiff("2015-01-31", "2015-02-01");
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>milis1::: 1425367717308
  milis2::: 1425194917308
  diff::: -172800000
  
  java.lang.Exception: Invalid End Date. End Date Must Be After Start Date
  </code></pre>
  
  <p>Here <em>2015-01-31</em> is start date and <em>2015-02-01</em> is end date. 
  As start date(2015-01-31) is coming as greater value in milliseconds than end date(2015-02-01) so its giving wrong result.</p>
  
  <p>So is this a problem with method <code>getTimeInMillis()</code> of <code>Calendar</code> class or I am doing something wrong?</p>