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

DateFormat.parse(String) returns Month Jan always

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 6u45
    • core-libs

      FULL PRODUCT VERSION :
      java version " 1.6.0_45 "
      Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      Function is used within JEE environment. switch Java 7 is excluded at the time!

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      None Eclipse Juno IDE

      A DESCRIPTION OF THE PROBLEM :
      Simple Program:
      private final static String DATE_FORMAT_STR = " yyyy-MM-DD HH:mm:ss " ;

      private final static String DATE_STR_1 = " 2012-12-17 14:29:15 " ;
      private final static String DATE_STR_2 = " 2013-08-23 11:53:18 " ;

      public static void main(String[] args) throws ParseException {
      DateFormat df = new SimpleDateFormat(DATE_FORMAT_STR);
      Date myDate = df.parse(DATE_STR_1);
      System.out.println( " date 1: " + myDate);
      Date myDate2 = df.parse(DATE_STR_2);
      System.out.println( " date 2: " + myDate2);
      Output:
      date 1:Tue Jan 17 14:29:15 CET 2012
      date 2:Wed Jan 23 11:53:18 CET 2013
      For DATE_STR_1 rather Dec is expected.
      For DATE_STR_2 rather Aug is expected.

      But both has Jan as output!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the programm snippet

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      For DATE_STR_1 rather Dec is expected.
      For DATE_STR_2 rather Aug is expected.
      ACTUAL -
      date 1:Tue Jan 17 14:29:15 CET 2012
      date 2:Wed Jan 23 11:53:18 CET 2013

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      private final static String DATE_FORMAT_STR = " yyyy-MM-DD HH:mm:ss " ;

      private final static String DATE_STR_1 = " 2012-12-17 14:29:15 " ;
      private final static String DATE_STR_2 = " 2013-08-23 11:53:18 " ;

      public static void main(String[] args) throws ParseException {
      DateFormat df = new SimpleDateFormat(DATE_FORMAT_STR);
      Date myDate = df.parse(DATE_STR_1);
      System.out.println( " date 1: " + myDate);
      Date myDate2 = df.parse(DATE_STR_2);
      System.out.println( " date 2: " + myDate2);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None actually

            okutsu Masayoshi Okutsu
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: