?
Solved

Add 2 hours to current timestamp in Java

Posted on 2012-04-02
6
Medium Priority
?
335 Views
Last Modified: 2013-01-25
Hi everyone,

Little weak in this area...

Im running a scheduler job using Java 1.5 and I pulling the record from the database, then getting the create timestamp of the record from the oracle database and then I want to add 2 hours to it and see if greater than the current time.  Basically Im delaying processing of a record until two hours have gone by.

Could some provide me a simple example of adding 2 hours to the timestamp and then checking against the current timestamp to see if it needs processed.
0
Comment
Question by:TheVeee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 37798190
you can use some sql

here is some info
http://stackoverflow.com/questions/257324/oracle-how-to-add-minutes-to-a-timestamp

or use java


Just compute the minutes and the timestamp as milliseconds and add them.
long t=theOldTimeStamp.getTime();
long m=minutes*60*1000

TimeStamp theNewTimestamp=new TimeStamp (t+m);

Open in new window

0
 
LVL 26

Accepted Solution

by:
ksivananth earned 1000 total points
ID: 37799514
the above one ignores nano secs, try this,

long time = ts.getTime() ;
time = time + ( 2 * 60 * 60 * 1000 ) ;
TimeStamp newTs = new TimeStamp( time ) ;
newTs.setNanos( ts.getNanos() ) ;
0
 
LVL 12

Expert Comment

by:Anuradha Goli
ID: 37806321
compute the hours as millisecs and assign as timestamp

(2*60*60*1000)+your current time
0
 
LVL 5

Assisted Solution

by:knsp
knsp earned 1000 total points
ID: 37896365
DateFormat formatter = new SimpleDateFormat("HH:mm:ss");  
 
try {  
    Date start = formatter.parse("09:11:59");  
    Long startMilli = start.getTime();          
    Long resultMilli = startMilli + 7200000; // adding 2 hrs in miliseconds      
    Date result = new Date(resultMilli);  
    System.out.println(formatter.format(result));    
} catch (ParseException ex) {  
    ex.printStackTrace();  
}
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 38818066
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question