United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 5088703 (fmt) %tl and %tI format specifiers print "0"/"00" instead of 12 for 12 PM
5088703 : (fmt) %tl and %tI format specifiers print "0"/"00" instead of 12 for 12 PM

Details
Type:
Bug
Submit Date:
2004-08-18
Status:
Resolved
Updated Date:
2004-11-06
Project Name:
JDK
Resolved Date:
2004-11-06
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.util
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
6

Related Reports
Backport:

Sub Tasks

Description
Name: rmT116609			Date: 08/18/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
SunOS parakeet 5.8 Generic_108528-27 sun4u sparc SUNW,Ultra-60


A DESCRIPTION OF THE PROBLEM :
According to the Javadoc documentation to print the hour part of a date in 12 hour format, you would use %tI.

http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#dt

'I'  Hour for the 12-hour clock, formatted as two digits with a leading zero as necessary, i.e. 01 - 12.

I found that if you print a time that has an hour of 12 PM, it will print 00 instead of 12.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Wed Aug 18 12:00:00 CDT 2004
12:00 PM

ACTUAL -
Wed Aug 18 12:00:00 CDT 2004
00:00 PM


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Test {
	public static void main(String[] args) {
		try {
			Calendar calendar = new GregorianCalendar(2004, 7, 18, 12, 0, 0);
			Date date = calendar.getTime();
			System.out.println(date);
			System.out.println(String.format("%tI:%tM %tP", date, date, date));
		}
		catch(Exception e) {
			e.printStackTrace();
		}
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
You can test for the 12 PM case and just create the string manually with a 12 instead of 00.
(Incident Review ID: 297472) 
======================================================================
###@###.### 10/8/04 22:37 GMT

                                    

Comments
SUGGESTED FIX

***************
*** 3771,3777 ****
  	    case DateTime.HOUR:        { // 'l' (1 - 12) -- like I
  		int i = t.get(Calendar.HOUR_OF_DAY);
  		if (c == DateTime.HOUR_0 || c == DateTime.HOUR)
! 		    i = (i == 0 ? 12 : i % 12);
  		Flags flags = (c == DateTime.HOUR_OF_DAY_0
  			       || c == DateTime.HOUR_0
  			       ? Flags.ZERO_PAD
--- 3771,3777 ----
  	    case DateTime.HOUR:        { // 'l' (1 - 12) -- like I
  		int i = t.get(Calendar.HOUR_OF_DAY);
  		if (c == DateTime.HOUR_0 || c == DateTime.HOUR)
! 		    i = (i == 0 || i == 12 ? 12 : i % 12);
  		Flags flags = (c == DateTime.HOUR_OF_DAY_0
  			       || c == DateTime.HOUR_0
  			       ? Flags.ZERO_PAD
###@###.### 10/8/04 22:37 GMT
                                     
2004-10-08
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-08-19
EVALUATION

oops.

Trivial fix should be applied as soon as possible.

-- iag@sfbay 2004-08-18
                                     
2004-08-18



Hardware and Software, Engineered to Work Together