Home Java LocalDateTime Methods isEqual() Java LocalDateTime isEqual() Method Definition In Java, a.isEqual(b) returns true if a and b are at the same point on the local timeline. It is the third question next to isBefore() and isAfter(): exactly one of the three is true for any pair.
For two LocalDateTime objects it gives the same answer as equals(). It exists because it also accepts date-times of other calendar systems.
An instance method of java.time.LocalDateTime (since Java 8): call it on a LocalDateTime object. Add import java.time.LocalDateTime; at the top of your file. It comes from ChronoLocalDateTime, which LocalDateTime implements.
Syntax Call it on one date-time and pass the other.
LocalDateTime a = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime b = LocalDateTime.of(2026, 3, 15, 10, 30, 0);
boolean same = a.isEqual(b); // true Call What it does a.isEqual(b)True if a and b are at the same local moment. a.equals(b)True if they are the same type and have the same values. a.compareTo(b) == 0The same test written with compareTo(). a.truncatedTo(unit).isEqual(b.truncatedTo(unit))Compares them while ignoring the smaller parts.
Exactly one of isBefore(), isEqual(), and isAfter() is true for any pair of date-times.
Library declarations // java.time.LocalDateTime
public boolean isEqual(ChronoLocalDateTime<?> other) Parameters Parameter Description other (ChronoLocalDateTime<?>)The date-time to compare with. It must not be null.
Return Value Return Value Description booleantrue if both are at the same moment on the local timeline, otherwise false.
Important
Both date-times are compared as local times. A LocalDateTime has no zone, so 10:30 in India and 10:30 in Japan are "equal" here, although they are different moments in the real world. Use ZonedDateTime.isEqual() to compare real moments. Passing null throws a NullPointerException.
Compare with Similar Methods Ways to compare date-times:
Java Examples 1. Same moment 2. One of three 3. Ignore seconds Example 1 — Check Whether Two Date-Times Are the Same Moment Compare equal values, values that differ by one minute, and the same pair written with seconds.
import java.time.LocalDateTime;
public class LdtIsEqualDemo {
public static void main(String[] args) {
LocalDateTime a = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime sameValue = LocalDateTime.of(2026, 3, 15, 10, 30, 0);
LocalDateTime later = LocalDateTime.of(2026, 3, 15, 10, 31);
System.out.println("a isEqual sameValue: " + a.isEqual(sameValue));
System.out.println("a isEqual later: " + a.isEqual(later));
System.out.println("a equals sameValue: " + a.equals(sameValue));
}
} a isEqual sameValue: true
a isEqual later: false
a equals sameValue: true How It Works Seconds written out. sameValue adds 0 seconds, which is the same moment as a.Same moment gives true. The first line prints true.One minute later gives false. The second line prints false.equals agrees. For two LocalDateTime objects, equals gives the same answer, so the last line prints true too.Example 2 — See That Exactly One of Three Is True Test the three comparison methods on a before, an equal, and an after pair.
import java.time.LocalDateTime;
public class LdtIsEqualThree {
public static void main(String[] args) {
LocalDateTime base = LocalDateTime.of(2026, 3, 15, 10, 30);
LocalDateTime[] others = {
LocalDateTime.of(2026, 3, 15, 9, 0),
LocalDateTime.of(2026, 3, 15, 10, 30),
LocalDateTime.of(2026, 3, 15, 18, 0)
};
for (LocalDateTime other : others) {
System.out.println(other.toLocalTime() + " -> before: " + base.isBefore(other)
+ ", equal: " + base.isEqual(other) + ", after: " + base.isAfter(other));
}
}
} 09:00 -> before: false, equal: false, after: true
10:30 -> before: false, equal: true, after: false
18:00 -> before: true, equal: false, after: false How It Works Three others. One is earlier than base, one is equal, and one is later.Look at each line. The text shows the three answers for the pair.Never two true at once. Exactly one of the three answers is true in every line.The order is from the point of view of base. Against 09:00, base is after. Against 10:30, it is equal. Against 18:00, it is before.Example 3 — Compare While Ignoring the Seconds Two times are 30 seconds apart. Compare them directly, and then after cutting both to the minute.
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
public class LdtIsEqualMinutes {
public static void main(String[] args) {
LocalDateTime a = LocalDateTime.of(2026, 3, 15, 10, 30, 15);
LocalDateTime b = LocalDateTime.of(2026, 3, 15, 10, 30, 45);
System.out.println("exact compare: " + a.isEqual(b));
LocalDateTime aMinute = a.truncatedTo(ChronoUnit.MINUTES);
LocalDateTime bMinute = b.truncatedTo(ChronoUnit.MINUTES);
System.out.println("to the minute: " + aMinute.isEqual(bMinute));
System.out.println("both became: " + aMinute);
}
} exact compare: false
to the minute: true
both became: 2026-03-15T10:30 How It Works Two times in the same minute. They are 10:30:15 and 10:30:45.An exact compare fails. The seconds differ, so isEqual is false.Cut to the minute. truncatedTo(ChronoUnit.MINUTES) sets the seconds and the fraction to zero.Now they match. Both become 10:30, so the comparison prints true.Frequently Asked Questions What is the difference between isEqual() and equals() for LocalDateTime? For two LocalDateTime objects they give the same answer. isEqual accepts date-times of other calendar systems, and equals accepts any object.
How do I compare two date-times ignoring seconds? Cut both with truncatedTo(ChronoUnit.MINUTES), then call isEqual() or equals().
Does isEqual() take the time zone into account? Not for LocalDateTime, which has no zone. ZonedDateTime.isEqual() compares the real instant.
Can isEqual() throw an exception? Only a NullPointerException, if you pass null.
How are isBefore(), isEqual(), and isAfter() related? For any pair of date-times, exactly one of the three returns true.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
10 people found this page helpful
Helpful Share Copy link Suggestion