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);
long t=tmpTimeStamp. getTime(); long m=delayMinutes*60*1000; targetDeliveryStamp= new Timestamp(t+m); java.
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!
println("Current Date and Time = " + calendar. getTime()); Now, let us increment the minutes using the calendar. add() method and Calendar.
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With