• Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P2 P2
    • None
    • 1.2.0
    • core-libs
    • None



      The following mail documents a problem with parsing
      that date February 29, 2000. I get the correct result
      in JDK 1.1.7 but an incorrect result in JDK 1.2.


      --Guy



      ------------- Begin Forwarded Message -------------


      X-Sender: ###@###.###
      Date: Fri, 09 Apr 1999 09:36:27 -0400
      To: Guy Steele - Sun Microsystems Labs <###@###.###>
      From: David Chase <###@###.###>


      ...


      Anyway, here's an example. It is supposed to fail in 1900,
      but not in in 2000.


      -------------------------------------------------------
      import java.util.TimeZone;
      import java.util.Date;
      import java.text.SimpleDateFormat;


      public class Bug
      {
        static public void main(String[] args)
        {
          String[] testStrings = {
            "28/02/1900",
            "29/02/1900", // should result in an exception
            "28/02/2000",
            "29/02/2000",
          };
          
          SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
          formatter.setLenient(false);
          formatter.setTimeZone(TimeZone.getDefault());
          for (int i = 0; i < testStrings.length; ++i) {
            System.out.println("For test string " + testStrings[i]);
            try {
              Date d = formatter.parse(testStrings[i]);
              System.out.println(" time = " + d.getTime());
              System.out.println(" result = " + d);
            }
            catch (Exception e) {
              System.out.println();
              e.printStackTrace();
            }
          }
        }
      }
      -------------------------------------------------------
      ...


      ------------- End Forwarded Message -------------

            nlindenbsunw Norbert Lindenberg (Inactive)
            gbrachasunw Gilad Bracha (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: