JDK-4074758 : Calendar.HOUR returns 0 for 12 am/pm instead of 12
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util:i18n
  • Affected Version: 1.1.3
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-08-27
  • Updated: 1998-02-17
  • Resolved: 1998-02-17
Related Reports
Relates :  
Relates :  
Description

Name: tb29552			Date: 08/27/97


The Calendar.HOUR in GregorianCalendar
returns 0 for 12 am/pm. This is not correct. In 12 
hour format, 12 am/pm is 12 am/pm and not 0. 

The calc of hour in GregorianCalendar (line 549 
of source in JDK1.1.3) calculates hour as a 
remainder of the HOUR_OF_DAY. If it is zero, it 
should be set to 12.

import java.util.*;

public class Test7 {
    public static void main(String[] args) {
        //Set system time to between 12-1 (am or pm) and then run

        GregorianCalendar cal = new GregorianCalendar();
        Date d = new Date();
        cal.setTime(d);
        System.out.println(d);
        System.out.println(cal.get(Calendar.HOUR)); //prints 0
        System.out.println(cal.get(Calendar.HOUR_OF_DAY));

    }
}

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

Comments
EVALUATION User error; use one- and zero-based field specifiers -ASL
11-06-2004

WORK AROUND Name: tb29552 Date: 08/27/97 ======================================================================
11-06-2004