ChronoLocalDateTime compareTo() method in Java with Examples
The compareTo() method of ChronoLocalDateTime interface in Java method compares this date to another date.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
default int compareTo(ChronoLocalDateTime other)
Parameter: This method accepts a parameter other which specifies the other date to compare to and it is not specifically null.
Return Value: It returns the comparator value which is negative if it is less else it is positive if it is greater.
Below programs illustrate the compareTo() method of ChronoLocalDateTime in Java:
2018-12-06T19:21:12 2018-12-06T19:21:12 0
2018-12-05T19:21:12 2018-12-06T19:21:12 1