将 Joda time Instant 转换为 Java time Instant

converting Joda time Instant to Java time Instant

我有一个 Instant (org.joda.time.Instant) 实例,我在一些 api 响应中得到了它。我有另一个来自 (java.time.Instant) 的实例,这是我从其他调用中获得的。现在,我想比较这两个对象以检查哪一个获得最新的对象。怎么可能?

joda.time 中的

getMillis() 可以与 java.time 中的 toEpochMilli() 进行比较。

Class 文档:

示例代码。

java.time.Instant myJavaInstant = 
    java.time.Instant.ofEpochMilli( myJodaInstant.getMillis() ) ;

走另一条路。

// Caution: Loss of data if the java.time.Instant has microsecond
// or nanosecond fraction of second.
org.joda.time.Instant myJodaInstant = 
    new org.joda.time.Instant( myJavaInstant.toEpochMilli() ); 

您可以从 joda Instant 转换为 java(日期时间和格式只是一个示例):

org.joda.time.Instant.parse("10.02.2017 13:45:32", DateTimeFormat.forPattern("dd.MM.yyyy HH:mm:ss")).toDate().toInstant()

所以你在你的 joda Instant 上调用 toDate()toInstant()