File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Date object always makes me cry; please help me out. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date object always makes me cry; please help me out." Watch "Date object always makes me cry; please help me out." New topic
Author

Date object always makes me cry; please help me out.

vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
hi friends,

I am back to you guys with a very easy question


Now i have a Date object and need to add some hours minutes and am pm value.

what should be precedence to set these fields in the calendar object. I get a bad date is current state; say am/pm value is not set correctly;

When i input
02:02 pm
output i get is
02:02 AM



Sridhar Santhanakrishnan
Ranch Hand

Joined: Mar 20, 2007
Posts: 317
Can you check what value you send for AM/PM? It should be 0 for AM and 1 for PM (I think).
vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
i have changed the code little bit; but no effect; Now the code is as givent below


When i input
12:12 am
i get to see; when debuging in IDE; till


it is 0 when calling


but after setting value to Calendar.HOUR_OF_DAY code it gets changed to 1.

I find it is peculiar of something i am not able to digest.

Please give a answer.


output i get is
12:12 PM



vijay shanker
Ranch Hand

Joined: Oct 26, 2007
Posts: 88
No answers;


This is very strange here.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9317
    
  17

Well since you are setting

calendar.set(Calendar.HOUR_OF_DAY, this.getHours());

So the code before it i.e.

calendar.set(Calendar.AM_PM, this.getAmpm());

Has no effect. Try using this

calendar.set(Calendar.HOUR, this.getHours());


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date object always makes me cry; please help me out.