>Calendar c = Calendar.getInstance();
>c.set(Calendar.AM_PM, Calendar.AM);
>System.out.println(c.get(Calendar.AM_PM));
c already contained a date and time timestamp. It already KNEW the
time was after noon. The AM_PM field would only be relevant if you
composed the field from bits and pieces including an hour.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
P.Hill - 19 Oct 2005 05:31 GMT
>>Calendar c = Calendar.getInstance();
>>c.set(Calendar.AM_PM, Calendar.AM);
>>System.out.println(c.get(Calendar.AM_PM));
>
> The AM_PM field would only be relevant if you
> composed the field from bits and pieces including an hour.
Curiously enough that is the feature and it IS documented:
"Inconsistent information. If fields conflict, the calendar will give
preference to fields set more recently. For example, when determining
the day, the calendar will look for one of the following combinations of
fields. The most recent combination, as determined by the most recently
set single field, will be used.
[...]
For the time of day:
HOUR_OF_DAY
AM_PM + HOUR
"
see
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html
So in your case it didn't come up with AM_PM and the HOUR _combination_
as having been set, so it used the old HOUR_OF_DAY. The solution is to
change HOUR when you change AM_PM which could include getting the
existing value, thus the following code results in
the value you expected:
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR, c.get(Calendar.HOUR));
c.set(Calendar.AM_PM, Calendar.AM);
System.out.println(c.get(Calendar.AM_PM));
-Paul