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
|