Solved

Add 2 hours to current timestamp in Java

Posted on 2012-04-02
6
266 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
6 Comments
 
LVL 15

Expert Comment

by:Ess Kay
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Python Assistance 7 31
create a gui in perl 3 42
advertisement module in core php 4 81
Checkbox and ListView in Android Layout 4 36
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now