Given two LocalTime parameters in Java, I want to be able to compare the two times and see if they are equal (the same time). How would I do this?
Compare using LocalTime instance methods: isBefore, isAfter, equals, and compareTo.
LocalTime lt1 = LocalTime.of( 14 , 17 ) ;
LocalTime lt2 = LocalTime.of( 21 , 29 ) ;
boolean same = lt1.equals( lt2 ) ;
equals versus isEqualBe aware than some java.time classes (other than LocalTime) carry an isEqual method in addition to the equals method inherited from Object, with different semantics.
For example:
LocalDate.isEqual versus LocalDate.equalsZonedDateTime.isEqual versus ZonedDateTime.equalsIf 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