JDK-4462302 : Different result from FORMAT method in java.text.SimpleDateFormat
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.3.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2001-05-23
  • Updated: 2001-05-24
  • Resolved: 2001-05-24
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Name: yyT116575			Date: 05/23/2001


java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

I found the different result when using FORMAT method in
java.text.SimpleDateFormat of JDK1.1.8 and JDK1.3.1.
     Result after formatting current date to "HHmmssSS" from beneath program
     - Using JDK1.1.8 has the same length (8).
     - Using JDK1.3.1 has not the same length (8 or 9).
   
--------------------------------------------------------------------------------
import java.text.SimpleDateFormat;
import java.util.*;

// There is different when we converts date using FormatDateTime by JDK1.1.8 and
 JDK1.3.1
class TestFormatDate {
  private static String FORMAT = "HHmmssSS";

  public static void main(String args[]) throws Throwable {
    for (int i=0; i < 10; i++) {
      Date d = new Date();
      SimpleDateFormat sdf = new SimpleDateFormat(FORMAT);
      String formatS = sdf.format(d);
      System.out.println("Format [" + formatS + ", " + formatS.length() + "]");

      double rand = Math.random();
      Thread.sleep(Math.round(rand * 100));
    }
  }
}
--------------------------------------------------------------------------------

Result from JDK1.1.8
     Format [16170253, 8]
     Format [16170259, 8]
     Format [16170266, 8]
     Format [16170271, 8]
     Format [16170276, 8]
     Format [16170286, 8]
     Format [16170297, 8]
     Format [16170302, 8]
     Format [16170307, 8]
     Format [16170312, 8]

Result from JDK1.3.1
     Format [160505643, 9]
     Format [160505828, 9]
     Format [160505918, 9]
     Format [16050618, 8]
     Format [16050668, 8]
     Format [160506128, 9]
     Format [160506148, 9]
     Format [160506198, 9]
     Format [160506218, 9]
     Format [160506238, 9]
(Review ID: 124873) 
======================================================================

Comments
EVALUATION This isn't a bug of JDK1.3.1's SimpleDateFormat but JDK1.1.8's. The results of JDK1.3.1 are correct. "SS" means that format() should return a StringBuffer of the millisecond number with *at least* 2 digits. If the digits of the given millisecond number is shorther than the digits of of "S", format() pads zero(s). Otherwise, if longer, format() return a longer StringBuffer than a given String of "S". yuka.kamiya@japan 2001-05-24 The behavior changes in 1.3 as the resolution of 4148168 and 4253490. The 1.1.8 behavior is a bug. masayoshi.okutsu@Eng 2001-05-24
24-05-2001