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

(cal) GregorianCalendar set method provides wrong result

XMLWordPrintable

    • b08
    • generic, x86
    • generic, windows_xp
    • Verified

      FULL PRODUCT VERSION :
      Java<TM> 2 Runtime Environment, Standard Edition <build 1.5.0_08-b03>
      Java HotSpot<TM> Client VM <build 1.5.0_08-b03, mixed mode, sharing>

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Window XP [ version 5.1.2600 ]

      A DESCRIPTION OF THE PROBLEM :
      The code is be below:

      public class test {
          public static void main(String[] args){
              try{
                  GregorianCalendar gc1=new GregorianCalendar(1,0,1,0,0,0);
                  gc1.set(Calendar.HOUR,13865672);
                  System.out.println(gc1.getTime());
                  
                  GregorianCalendar gc2=new GregorianCalendar(1,0,1,0,0,0);
                  gc2.set(Calendar.HOUR,13865696);
                  System.out.println(gc2.getTime());

              }catch(Exception ex){ ex.printStackTrace();}
          }
      }

      The output of the above code is:

      Thu Oct 04 08:00:00 CST 1582
      Sun Oct 17 08:00:00 CST 1582
      Press any key to continue...

      We can see that:
      13865696-13865672=24
      Only one day. But first line output 04while the second line output 17.
      Strange!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public class test {
          public static void main(String[] args){
              try{
                  GregorianCalendar gc1=new GregorianCalendar(1,0,1,0,0,0);
                  gc1.set(Calendar.HOUR,13865672);
                  System.out.println(gc1.getTime());
                  
                  GregorianCalendar gc2=new GregorianCalendar(1,0,1,0,0,0);
                  gc2.set(Calendar.HOUR,13865696);
                  System.out.println(gc2.getTime());

              }catch(Exception ex){ ex.printStackTrace();}
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Thu Oct 04 08:00:00 CST 1582
      Fri Oct 05 08:00:00 CST 1582
      Press any key to continue...
      ACTUAL -
      Thu Oct 04 08:00:00 CST 1582
      Sun Oct 17 08:00:00 CST 1582
      Press any key to continue...

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class test {
          public static void main(String[] args){
              try{
                  GregorianCalendar gc1=new GregorianCalendar(1,0,1,0,0,0);
                  gc1.set(Calendar.HOUR,13865672);
                  System.out.println(gc1.getTime());
                  
                  GregorianCalendar gc2=new GregorianCalendar(1,0,1,0,0,0);
                  gc2.set(Calendar.HOUR,13865696);
                  System.out.println(gc2.getTime());

              }catch(Exception ex){ ex.printStackTrace();}
          }
      }
      ---------- END SOURCE ----------

            okutsu Masayoshi Okutsu
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: