Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add time to a timestamp?

I need to add 14 minutes and 59 seconds to an unknown time in an array. How do I do this? This is what I have so far:

Date duration = df.parse("0000-00-00 00:14:59");

arrayOpportunity[2] = arrayOpportunity[2] + duration;

The time is not being changed. Thanks!

I have done my research. I cant paste the entire code I have. But mainly I didnt want to make you read it all. Just looking for a simple answer of how to add two timestamps.

like image 669
Samuel Knox Avatar asked Oct 24 '12 14:10

Samuel Knox


1 Answers

If you are talking about a java.sql.Timestamp, it has a method called setTime. java.util.Date has a setTime method as well for that sort of thing.

You could something like this:

static final Long duration = ((14 * 60) + 59) * 1000;

oldTimestamp.setTime(oldTimestamp.getTime() + duration);
like image 91
Mike Thomsen Avatar answered Oct 14 '22 12:10

Mike Thomsen