title: How does java.sql.Date work with negative dates?
body: <p>I had a situation where the Java runtime returned sort of "inverted" millisecond values when reading dates from the database (in <code>java.sql.Date</code>). The millisecond value was approximately the same amount of days, but counted backwards from year 0.</p>
  
  <p>The problem was solved by just restarting the Java runtime.</p>
  
  <p>But: I found out that Java handles these "inverted" values almost correctly except of the week day.</p>
  
  <p>When you run the following code:</p>
  
  <pre><code>System.out.println(new java.util.Date(253402214400000l));
  System.out.println(new java.util.Date(-377648784000000l));
  </code></pre>
  
  <p>You will get the following output:</p>
  
  <pre><code>Fri Dec 31 01:00:00 CET 9999
  Tue Dec 31 01:00:00 CET 9999
  </code></pre>
  
  <p>Another example:</p>
  
  <pre><code>System.out.println(new java.util.Date(-294192000000l));
  System.out.println(new java.util.Date(-123967324800000l));
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Mon Sep 05 01:00:00 CET 1960
  Mon Sep 05 01:00:00 CET 1960
  </code></pre>
  
  <p>When using online converters, the result will be different for the particular second line. It will result in a negative date (the year is negative) close to the real, positive date:</p>
  
  <pre><code>Example1:
  253402214400000 = Fri Dec 31 9999 01:00:00
  -377648784000000 = Tue Oct 15 -9998 02:00:00
  
  Example 2:
  -294192000000 = Mon Sep 05 1960 02:00:00
  -123967324800000 = Mon Aug 19 -1959 02:00:00
  </code></pre>
  
  <p>I have not found any information about this "topic".</p>
  
  <p>So, what's the myth behind "inverted" dates? Why does Java handle them almost correctly? And what is the sense of a JDBC <code>ResultSet</code> returning "inverted" millisecond values when calling <code>resultSet.getDate(1).getTime()</code>?</p>