在Java中单调增加时间? [英] Monotonically increasing time in Java?

查看:234
本文介绍了在Java中单调增加时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java应用程序中,我希望能够在操作开始时获取时间戳,并能够定期检查操作运行的时间。问题是:我不希望受到网络时间协议的影响,或者管理员改变时间,或任何可以突然调整时间的东西。我想要一个单调增加的时间价值。我相信这会排除java.util.Date,Time和Calendar。

In a Java application I want to be able to take a timestamp at the start of an operation and be able to periodically check how long the operation has been running. The catch is: I do not want to be impacted by the Network Time Protocol moving the clock around, or the admin changing the time, or anything which can abruptly adjust the time of day. I want a monotonically increasing time value. I believe this rules out java.util.Date, Time, and Calendar.

JRE中是否存在单调递增时间戳的来源?

Is there some source of a monotonically increasing timestamp in the JRE?

推荐答案

您是否考虑过使用 System.nanoTime()

它只对计算经过的时间有意义两个事件之间。由于文档声明它与任何系统或墙壁时间无关,我相信它可以用于你的坐垫。

It is only meaningful in working out elapsed time between two events. Since the documentation states that it is not related to any system or wall time I believe it could be used in your sitatuion.

这篇关于在Java中单调增加时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆