converting Joda time Instant to Java time Instant

user123475 :

I have an instance of Instant (org.joda.time.Instant) which I get in some api response. I have another instance from (java.time.Instant) which I get from some other call. Now, I want to compare these two object to check which one get the latest one. How would it be possible?

discipliuned :

getMillis() from joda.time can be compared to toEpochMilli() from java.time.

Class documentation:

Example code.

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

Going the other way.

// 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() ); 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=448235&siteId=1