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

SimpleDateFormat parsing years -1 through -9 to 1999 through 1991.

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      007
    • CPU:
      generic
    • OS:
      solaris_2.6

      Backports

        Description


        The way the negative years are handled using the SimpleDateFormat
        and DateFormat classes is strange, even with the setLenient(false)
        being called :
        format: MM/dd/yyyy or MM/dd/yyy or MM/dd/yy

        the year -1 is parsed to 1999
        the year -2 is parsed to 1998
        .
        .
        .
        the year -9 is parsed to 1991


        It doesn't make any sense for the year -1 to be parsed
        to 1999 as is the same for the rest (-2 to -9).

        ------------------------------------------------------
        The following test case can be run to verify the above.

        /**
         * You can change the format string to cater to
         * 3 or 4 digit years to check the ouput.
         */


        import java.util.*;
        import java.text.*;

        class t3 {

                public static void main(String args[]){
                        try {
                                DateFormat formatter = new SimpleDateFormat ("MM/dd/yy");
                                formatter.setLenient(false);
                                String s = "02/18/-";
                                Date d = null;

                                System.out.println("format string is: MM/dd/yy");
                                for(int i=1; i<10; i++) {
                                        d = formatter.parse(s+i);
                                        System.out.println(s + i + " parsed to " + d.toString());
                                }
                        }
                        catch(Exception e) {
                                System.out.println("Format exception" + e);
                        }
                }
        }


        This also happens in jdk1.1.6.
        john.s.lee@Eng 1998-11-02

        This continues to happen in jdk1.1.7

        This continues to happen in jdk1.1.8h build.
        john.s.lee@Eng 1999-02-25

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                okutsu Masayoshi Okutsu
                Reporter:
                foliversunw Fred Oliver (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: