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

java.text.SimpleDateFormat Month Conversion Bug

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.2.9200]

      A DESCRIPTION OF THE PROBLEM :
      when the local time is 31/07/2013

      then i set the month in calendar object to 8

      because i set calender month to 8 and it is zero-index base
      then the month must be month 9 = (September)

      i notice that this error occured when the current day 31/07/2013


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1- change the local time to be 31/07/2013
      2- execute the code
             Calendar calendar = new GregorianCalendar();

              System.out.println( " Current Date: " + sdf.format(calendar.getTime()));
              
              calendar.set(Calendar.MONTH, 8);
              
              sdf = new SimpleDateFormat( " dd/MM/yyyy " );
              System.out.println( " Changed Date: " + sdf.format(calendar.getTime()));

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Current Date: 31/07/2013
      Changed Date: 31/09/2013
      ACTUAL -
      Current Date: 31/07/2013
      Changed Date: 01/10/2013

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.text.SimpleDateFormat;
      import java.util.Calendar;
      import java.util.GregorianCalendar;


      public class TimeTest {
            public static void main(String[] args) {
      SimpleDateFormat sdf = new SimpleDateFormat( " dd/MM/yyyy " );
              Calendar calendar = new GregorianCalendar();

              System.out.println( " Current Date: " + sdf.format(calendar.getTime()));
              
              calendar.set(Calendar.MONTH, 8);
              
              sdf = new SimpleDateFormat( " dd/MM/yyyy " );
              System.out.println( " Changed Date: " + sdf.format(calendar.getTime()));
      }

      }
      ---------- END SOURCE ----------

      SUPPORT :
      YES

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: