Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

12 noon behavior in Calendar - Java 5

807591Mar 22 2008 — edited Mar 22 2008
I am not able to set a particular date to 12 noon. I have read a bunch of posts, but I do not see what I am doing wrong. When I try to set 03/01/2008 12:30 PM, the Calendar keeps coming back with 00 for the hour. I have tried setting HOUR_OF_DAY to 12, and I have tried the other approach setting HOUR = 0 and AM_PM to PM, but I get the same results. I also tried setting setLenient(false). How do you set a Calendar to 12 noon in Java 5?

Thanks.
// Set year, month, day, hour and minute attributes of calendar instance
		
calendar.set(Calendar.YEAR,  year.intValue());
calendar.set(Calendar.MONTH, TimestampUtility.translateMonthForCalendar(month.intValue()));
calendar.set(Calendar.DAY_OF_MONTH, day.intValue());
calendar.set(Calendar.MINUTE, minute.intValue());
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.HOUR_OF_DAY, hour.intValue());
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 19 2008
Added on Mar 22 2008
6 comments
1,809 views