Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add minutes to timestamp- most efficient way

Tags:

java

timestamp

I have to write a java code to add minutes(delayminutes) to a timestamp(tmpTimeStamp). This is what I have. I was wondering if this is an efficient way to do this or if there is a better way.

long t=tmpTimeStamp.getTime();
long m=delayMinutes*60*1000;
targetDeliveryStamp= new Timestamp(t+m);
like image 685
Lisa Avatar asked Oct 24 '13 14:10

Lisa


People also ask

How do you add minutes to a Timestamp?

long t=tmpTimeStamp. getTime(); long m=delayMinutes*60*1000; targetDeliveryStamp= new Timestamp(t+m); java.

How to add minutes to datetime in pandas?

Use the timedelta() class from the datetime module to add minutes to datetime, e.g. result = dt + timedelta(minutes=10) . The timedelta class can be passed a minutes argument and adds the specified number of minutes to the datetime. Copied!

How to add minutes to date time in Java?

println("Current Date and Time = " + calendar. getTime()); Now, let us increment the minutes using the calendar. add() method and Calendar.


1 Answers

That's pretty good. You can be slightly more efficient and avoid object construction overhead if you can reuse your temporary Timestamp:

tmpTimeStamp.setTime(tmpTimeStamp.getTime() + TimeUnit.MINUTES.toMillis(delayMinutes));
like image 79
lreeder Avatar answered Sep 23 '22 19:09

lreeder