• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to Add Hours to current date & time stamp

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could just wait, say, 12 hours.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u keith burch & Stan James . It did work.

Regards,
Murali
 
reply
    Bookmark Topic Watch Topic
  • New Topic