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?
Correct Option: D. In java 8,we are asked to migrate to java. time (JSR-310) which is a core part of the JDK which replaces joda library project.
Joda-Time is an API created by joda.org which offers better classes and having efficient methods to handle date and time than classes from java. util package like Calendar, Gregorian Calendar, Date, etc. This API is included in Java 8.0 with the java.
So the short answer to your question is: YES (deprecated).
In Java language, the Instant Class is used to represent the specific time instant on the current timeline. The Instant Class extends the Object Class and implements the Comparable interface.
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() );
You can convert from joda Instant to java's (the datetime and formatting are just an example):
org.joda.time.Instant.parse("10.02.2017 13:45:32", DateTimeFormat.forPattern("dd.MM.yyyy HH:mm:ss")).toDate().toInstant()
So you call toDate()
and toInstant()
on your joda Instant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With