title: Problems with the Date 31-12-9999 in java
body: <p>My program needs to represent this date as a java.sql.date object , but it seems that when I create a new date (using the calendar) and set it to '9999-12-31' and finally convert this java.util.date object to a java.sql.date object, this date is converted to something like '000-01-31'.</p>
  
  <pre><code>Calendar calendar = Calendar.getInstance();
  calendar.set(9999, 12, 31);
  infinityDate = new java.sql.Date(normalizeDate(calendar.getTime()).getTime());
  </code></pre>
  
  <p>infinityDate should be 31-12-9999
  but when my code reaches here :</p>
  
  <pre><code>if(otherDate.equals(infinityDate))
  {// Do stuff}
  </code></pre>
  
  <p>It never goes into the if condition as the infinityDate has for some reason been changed to 31-01-000, even though otherDate is infact '31-12-9999'.</p>
  
  <p>The fact that otherDate is 31-12-9999 tells me that java can represent this dates , but for some reason , when I construct it using a calendar it changes the date. (otherDate comes from a jdbc statement which fetches data from a database)</p>
  
  <p>This reference date '31-12-9999' has been fixed by some client , so it cannot be changed and my program has to be able to compare some incoming date values with this.
  Does anyone know why this is happening , I realize that <a href="http://en.wikipedia.org/wiki/Year_10,000_problem" rel="nofollow">http://en.wikipedia.org/wiki/Year_10,000_problem</a> may be a problem for dates after year 9999 , but I should be safe by a day.</p>
  
  <p>EDIT : The Normalize date method only  "normalizes the given date to midnight of that day"</p>
  
  <pre><code>    private static java.util.Date normalizeDate(java.util.Date date) {
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(date);
      calendar.set(Calendar.HOUR_OF_DAY, 0);
      calendar.set(Calendar.MINUTE, 0);
      calendar.set(Calendar.SECOND, 0);
      calendar.set(Calendar.MILLISECOND, 0);
      date = calendar.getTime();
  
      return date;
  }
  </code></pre>
  
  <p>But , this issue was appearing before I was normalizing the date , I normalized it in an attempt to fix this.</p>