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));
}
}
======================================================================