Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What version of Java are you using and on what OS? Do you really need to store dates in the years 0 and 9999, or are you just using these as "negative infinity" and "positive infinity" values? How exactly do you see that the calendar is a Julian calendar?</p> <p>I tried this:</p> <pre><code>Calendar cal = Calendar.getInstance(); cal.set(0, Calendar.JANUARY, 1); Date d1 = cal.getTime(); cal.set(9999, Calendar.DECEMBER, 31); Date d2 = cal.getTime(); System.out.println(d1); System.out.println(d2); </code></pre> <p>Output (on Windows XP, using Sun Java 1.6.0_16):</p> <pre><code>Thu Jan 01 09:53:56 CET 1 java.util.Date Tue Dec 31 09:53:56 CET 9999 java.util.Date </code></pre> <p>It changes the year 0 to the year 1. Changing the code to use a second Calendar object for the second date:</p> <pre><code>Calendar cal = Calendar.getInstance(); cal.set(0, Calendar.JANUARY, 1); Date d1 = cal.getTime(); Calendar cal2 = Calendar.getInstance(); cal2.set(9999, Calendar.DECEMBER, 31); Date d2 = cal2.getTime(); System.out.println(d1); System.out.println(d2); </code></pre> <p>This does not change anything to the output or the content of the two <code>Date</code> objects.</p> <p>Note: Beware that integer literals that start with a 0, such as <code>0000</code> in your code, will be interpreted as octal numbers by the Java compiler. That doesn't matter in this case because the number is 0, but you should not prepend integer literals with zeroes if you don't mean them as octal numbers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload