java中的当前时间(以微秒为单位) [英] Current time in microseconds in java

查看:808
本文介绍了java中的当前时间(以微秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Unix系统上,有没有办法在Java中获得具有微秒级精度的时间戳?类似C的 gettimeofday 函数。

On a Unix system, is there a way to get a timestamp with microsecond level accuracy in Java? Something like C's gettimeofday function.

推荐答案

不,Java没有拥有那种能力。

No, Java doesn't have that ability.

它确实有System.nanoTime(),但这只是给出了一些先前已知时间的偏移量。因此,虽然您不能从中获取绝对数,但您可以使用它来测量纳秒(或更高)的精度。

It does have System.nanoTime(), but that just gives an offset from some previously known time. So whilst you can't take the absolute number from this, you can use it to measure nanosecond (or higher) precision.

请注意,JavaDoc说虽然这提供了纳秒精度,这并不意味着纳秒精度。因此,取一些适当大的返回值模数。

Note that the JavaDoc says that whilst this provides nanosecond precision, that doesn't mean nanosecond accuracy. So take some suitably large modulus of the return value.

这篇关于java中的当前时间(以微秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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