San*_*Rey 5 java datetime java-8
我想知道是否存在一种转换java.time.OffsetDateTime
为毫秒的方法,但是我不知道这是否是最好的方法:
book.getInteractionDuration().getStartTimeStamp().toEpochSecond()*1000
Run Code Online (Sandbox Code Playgroud)
Jon*_*eet 10
我只是将转换OffsetDateTime
为Instant
,然后使用toEpochMilli
:
long millis = book.getInteractionDuration().getStartTimeStamp().toInstant().toEpochMilli();
Run Code Online (Sandbox Code Playgroud)
不同于toEpochSecond()
,这种方法不会比需要毫秒而不是纳秒所固有的精度损失更多。
小智 10
尝试这个:
long millis = offsetDateTime.toInstant().toEpochMilli();
Run Code Online (Sandbox Code Playgroud)