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

(fmt) %tl and %tI format specifiers print "0"/"00" instead of 12 for 12 PM

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 5.0
    • core-libs
    • b12
    • x86
    • windows_xp

        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

              iris Iris Clark
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: