JDK-4148168 : Missing digits in millisecond format in SimpleDateFormat
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 1998-06-12
  • Updated: 1999-09-16
  • Resolved: 1999-09-16
Related Reports
Relates :  
Description

Name: mf23781			Date: 06/12/98


In the SimpleDateFormat only 3 didgits can be used for the millisecond field.
The pattern I have is required for DB2 ISO Timestamp
format.  It requires  6 digits milliseconds.  For now, I am forced 
to concatenate 3 zero and a single quote at the end before I can pass it 
to DB2, which I don't think is a correct way to do... 

NOTE:  the ISOPattern consist two single quote at the beginning and the end
of the pattern.  
          **** Not double quote. ***** 


Here is the code to reproduce the bug: 

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

class MillisecondTest
{
	public static void main(String[] args)
	{ 
		new MillisecondTest();
	}

	MillisecondTest()
	{
		Date aGMTDate = new Date();       
		String ISOPattern = "''yyyy-MM-dd-hh.mm.ss.SSSSSS''";       
		SimpleDateFormat aSimpleDF = ( SimpleDateFormat)DateFormat.getDateTimeInstance();       
		aSimpleDF.applyPattern( ISOPattern );       
		System.out.println( "a Pattern = " + aSimpleDF.toPattern() );       
		System.out.println( "a format = " + aSimpleDF.format( aGMTDate )  );  
	}
}

Here is the Output: 
 
a Pattern = ''yyyy-MM-dd-hh.mm.ss.SSSSSS''       
a format = '1998-05-20-10.09.31.043' 

The expected output should be:       

a format = '1998-05-20-10.09.31.043000' 
Three digits from millisecond (S) field is missing.  

======================================================================

Comments
EVALUATION This is a legitimate problem in the locale data; I'm reassigning to the person handling this area. The fix, as noted in the Chan/Lee/Kramer book and as agreed to by Mark Davis and others, is to add three millisecond digits (I think that's ".SSS") to the end of every FULL time format. alan.liu@eng 1999-03-17 Oops; I got this confused with 4116693. This is a separate bug which should still be open; I'm going to reopen it and assign it to the responsible engineer. This bug is actually a general problem with the handling of digits by SimpleDateFormat. SimpleDateFortmat doesn't handle large numbers of digits in any field (e.g., pattern "hhhhhhhhhhhhhhhhhhhhh"). Although this may be unusual, there is no reason it shouldn't work, according to the spec. The millisecond field has other problems specific to it, since it is to the right of the decimal point. For example, the string "1.4" is parsed to 1 second, 4 ms, with the pattern "s.S". It should be 400 ms. All of these problems underlie this bug report, and should be fixed together. The fix is not difficult. alan.liu@eng 1999-05-12 The fix in 'kestrel-beta' has been broken the spec and backed out by bug #4253490. Milliseconds, as the value allowed to be '0' to '999', not six digit in Java Date/Calendar world. If the user want to have 6 digit output, use 'SSS000' for the pattern. This problem is going to be closed as 'not a bug', instead of 'fixed'. koushi.takahashi@japan 1999-09-16
16-09-1999