• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Add Hours to current date & time stamp  RSS feed

 
Murali Mohan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a requirement that , I have to add 12 hours to current date & time stamp. The Calendar add function is not working when I use with hours.(The same function is working for days).

Can u pls let me know , any alternative for it?

Regards,
Murali
 
keith burch
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using the Calendar.HOUR field number, it will not look like it is being modified by adding 12 to it unless you also check the AM/PM setting. Try it using the Calendar. HOUR_OF_DAY field.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened with Calendar.add( Calendar.HOUR, n )? I think I've used that before. Maybe HOUR_OF_DAY?

You could also get the time in milliseconds, add to that, then convert back. Be sure all your calculations are longs or you can get a truncated int answer.
 
u johansson
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As usual, know what you're doing, or ask the highly paid analysist to come up with a formula you can use.
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could just wait, say, 12 hours.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by u johansson:
As usual, know what you're doing, or ask the highly paid analysist to come up with a formula you can use.


Why? It's a simple problem that Stan has already answered. Or did I miss some sarcasm here?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u johansson, please check your private messages. Thank you.
 
Murali Mohan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u keith burch & Stan James . It did work.

Regards,
Murali
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!