Convert Instant to microseconds from Epoch time

前端 未结 3 901
一个人的身影
一个人的身影 2021-02-13 04:51

In Instant there are methods:

  • toEpochMilli which converts this instant to the number of milliseconds from the epoch of 1970-01-01T00:00:00Z
3条回答
  •  无人共我
    2021-02-13 05:08

    As part of java.time, there are units under java.time.temporal.ChronoUnit that are useful for getting the difference between two points in time as a number in nearly any unit you please. e.g.

    import java.time.Instant;
    import java.time.temporal.ChronoUnit;
    
    ChronoUnit.MICROS.between(Instant.EPOCH, Instant.now())
    

    gives the microseconds since epoch for that Instant as a long.

提交回复
热议问题