title: Java.util.Calendar - milliseconds since Jan 1, 1970
body: <p>Program followed by output.  Someone please explain to me why 10,000,000 milliseconds from Jan 1, 1970 is November 31, 1969.  Well, someone please explain what's wrong with my assumption that the first test should produce a time 10,000,000 milliseconds from Jan 1, 1970.  Numbers smaller than 10,000,000 produce the same result.</p>
  
  <pre><code>public static void main(String[] args) {
  
      String x = "10000000";
      long l = new Long(x).longValue();
      System.out.println("Long value: " + l);
  
      Calendar c = new GregorianCalendar();
      c.setTimeInMillis(l);
      System.out.println("Calendar time in Millis: " + c.getTimeInMillis());
  
      String origDate = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH);  
      System.out.println("Date in YYYY-MM-DD format: " + origDate);
  
      x = "1000000000000";
      l = new Long(x).longValue();
      System.out.println("\nLong value: " + l);
  
      c.setTimeInMillis(l);
      System.out.println("Calendar time in Millis: " + c.getTimeInMillis());
  
      origDate = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH) + "-" + c.get(Calendar.DAY_OF_MONTH);  
      System.out.println("Date in YYYY-MM-DD format: " + origDate);
  }
  </code></pre>
  
  <blockquote>
    <p>Long value: 10000000</p>
    
    <p>Calendar time in Millis: 10000000</p>
    
    <p>Date in YYYY-MM-DD format: 1969-11-31</p>
    
    <p>Long value: 1000000000000</p>
    
    <p>Calendar time in Millis: 1000000000000</p>
    
    <p>Date in YYYY-MM-DD format: 2001-8-8</p>
  </blockquote>