Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
vijay shanker
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No answers;


This is very strange here.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic