Any new method to get current time with accuracy in microseconds in Java now?

后端 未结 3 522
清歌不尽
清歌不尽 2020-12-11 01:40

I checked the below page that there is no method to get current time with accuracy in microsecond in Java in 2009.
Current time in microseconds in java

The best

3条回答
  •  失恋的感觉
    2020-12-11 02:21

    Another way to get current time from the new Java 8 java.time is the Clock class

    Clock.systemUTC().millis()
    

    gives current time in millis (long value millis since epoch) or

    Clock.systemUTC().instant()
    

    returns an instance of Instant class "which represents the start of a nanosecond on the timeline" according to the official Oracle Java tutorial. The tutorial shows how to work with the new class, convert to local or UTC or zoned date time, etc

提交回复
热议问题