Converting Time in Joda Instant on Java

I have an Instant instance (org.joda.time.Instant) that I get in some api response. I have another instance from (java.time.Instant) that I get from another call. Now I want to compare these two objects to check which one to get the last one. How is this possible?

+4
source share
2 answers

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

Class Documentation:

Sample 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() ); 
+8
source

joda Instant java (datetime - ):

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

, toDate() toInstant() joda Instant.

0

Source: https://habr.com/ru/post/1648822/


All Articles