Java 将分钟添加到时间戳 - 最有效的方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19568549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
add minutes to timestamp- most efficient way
提问by Lisa
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.
我必须编写一个java代码来将分钟(延迟分钟)添加到时间戳(tmpTimeStamp)。这就是我所拥有的。我想知道这是否是一种有效的方法,或者是否有更好的方法。
long t=tmpTimeStamp.getTime();
long m=delayMinutes*60*1000;
targetDeliveryStamp= new Timestamp(t+m);
采纳答案by lreeder
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));