Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4180453

SimpleDateFormat("MM/dd/yyyy") parses 10/28/98 but will not parse 10/28/00

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.2.0
    • core-libs
    • sparc
    • solaris_2.5.1



      Name: tb29552 Date: 10/09/98


      /*
      The following code:
          sdf = new SimpleDateFormat("MM/dd/yyyy");
          sdf.setLenient(false);
          java.util.Date d = sdf.parse("10/28/98");
      will NOT throw a ParseException. Furthermore,
      d.toString() will print as:
          Sat Oct 28 00:00:00 PDT 0098

      And yet:
          sdf = new SimpleDateFormat("MM/dd/yyyy");
          sdf.setLenient(false);
          java.util.Date d = sdf.parse("10/28/00");
      throws a ParseException as expected.

      */
      import java.text.*;
      import java.util.*;
      class DateParseTest {
        public static void outputMessage(){
          System.out.println("java.version = " +
                             System.getProperty("java.version"));
          System.out.println("Operating System Name = " +
                             System.getProperty("os.name"));
          System.out.println("Operating system architecture = " +
                             System.getProperty("os.arch"));
          System.out.println("Operating system version = " +
                             System.getProperty("os.version") + "\n");
        }

        public static void main(String[] args){
          outputMessage();
          SimpleDateFormat sdf1;
          SimpleDateFormat sdf2;

          try {
            sdf1 = new SimpleDateFormat("MM/dd/yyyy");
            sdf1.setLenient(false);
            java.util.Date d1 = sdf1.parse("10/28/98");
            System.out.println("d1 is: " + d1.toString());

            sdf2 = new SimpleDateFormat("MM/dd/yyyy");
            sdf2.setLenient(false);
            java.util.Date d2 = sdf2.parse("10/28/00");
            System.out.println("d2 is: " + d2.toString());
          } catch (java.text.ParseException ex) {
            ex.printStackTrace();
          }
        }
      }

      (Review ID: 40256)
      ======================================================================

            aliusunw Alan Liu (Inactive)
            tbell Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: