Java LocalDateTime isEqual() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Java 8+

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.

Java
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
CallWhat 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
// java.time.LocalDateTime
public boolean isEqual(ChronoLocalDateTime<?> other)

Parameters

ParameterDescription
other (ChronoLocalDateTime<?>)The date-time to compare with. It must not be null.

Return Value

Return ValueDescription
booleantrue if both are at the same moment on the local timeline, otherwise false.

Compare with Similar Methods

Ways to compare date-times:

MethodHow it differs
equals(obj)Checks the type and the values. Accepts any object, even null.
isBefore(other)True if this is earlier.
isAfter(other)True if this is later.

Java Examples

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.

Java
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));
    }
}

How It Works

  1. Seconds written out. sameValue adds 0 seconds, which is the same moment as a.
  2. Same moment gives true. The first line prints true.
  3. One minute later gives false. The second line prints false.
  4. 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.

Java
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));
        }
    }
}

How It Works

  1. Three others. One is earlier than base, one is equal, and one is later.
  2. Look at each line. The text shows the three answers for the pair.
  3. Never two true at once. Exactly one of the three answers is true in every line.
  4. 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.

Java
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);
    }
}

How It Works

  1. Two times in the same minute. They are 10:30:15 and 10:30:45.
  2. An exact compare fails. The seconds differ, so isEqual is false.
  3. Cut to the minute. truncatedTo(ChronoUnit.MINUTES) sets the seconds and the fraction to zero.
  4. Now they match. Both become 10:30, so the comparison prints true.

Frequently Asked Questions

For two LocalDateTime objects they give the same answer. isEqual accepts date-times of other calendar systems, and equals accepts any object.
Cut both with truncatedTo(ChronoUnit.MINUTES), then call isEqual() or equals().
Not for LocalDateTime, which has no zone. ZonedDateTime.isEqual() compares the real instant.
Only a NullPointerException, if you pass null.
For any pair of date-times, exactly one of the three returns true.

Next: isSupported()

Check if a field or a unit can be used with this date-time.

isSupported() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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