Java LocalDateTime isAfter() Method

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

Definition

In Java, a.isAfter(b) returns true if a is later than b on the timeline, and false if it is earlier or exactly the same.

It is easier to read than compareTo(), and it is the usual way to ask questions such as "is the deadline over?".

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 deadline = LocalDateTime.of(2026, 3, 15, 17, 0);
LocalDateTime submitted = LocalDateTime.of(2026, 3, 15, 17, 1);

boolean late = submitted.isAfter(deadline);   // true
CallWhat it does
a.isAfter(b)True if a is later than b.
a.isBefore(b)True if a is earlier than b.
a.isEqual(b)True if they are at the same moment.
a.compareTo(b) > 0The same test written with compareTo().

a.isAfter(b) is the same as b.isBefore(a).

Library declarations
Java
// java.time.LocalDateTime
public boolean isAfter(ChronoLocalDateTime<?> other)

Parameters

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

Return Value

Return ValueDescription
booleantrue if this date-time is later than other, otherwise false.

Compare with Similar Methods

Ways to compare date-times:

MethodHow it differs
isBefore(other)The opposite question: is this earlier?
isEqual(other)Is this exactly the same moment?
compareTo(other)Gives a number for the order, which sorting uses.

Java Examples

Example 1 — Check If a Submission Is Late

The deadline is 17:00. Check three submission times.

Java
import java.time.LocalDateTime;

public class LdtIsAfterDeadline {
    public static void main(String[] args) {
        LocalDateTime deadline = LocalDateTime.of(2026, 3, 15, 17, 0);

        LocalDateTime onTime = LocalDateTime.of(2026, 3, 15, 16, 59);
        LocalDateTime justLate = LocalDateTime.of(2026, 3, 15, 17, 1);
        LocalDateTime nextDay = LocalDateTime.of(2026, 3, 16, 9, 0);

        System.out.println("16:59 late: " + onTime.isAfter(deadline));
        System.out.println("17:01 late: " + justLate.isAfter(deadline));
        System.out.println("next day late: " + nextDay.isAfter(deadline));
    }
}

How It Works

  1. A fixed deadline. 17:00 on 15 March 2026.
  2. One minute early. 16:59 is not after the deadline, so the answer is false.
  3. One minute late. 17:01 is after it, so the answer is true.
  4. The date counts too. 09:00 the next day is also after the deadline, because the date is compared first.

Example 2 — See That Equal Is Not After

Compare a date-time with itself, and with one nanosecond later.

Java
import java.time.LocalDateTime;

public class LdtIsAfterEqual {
    public static void main(String[] args) {
        LocalDateTime a = LocalDateTime.of(2026, 3, 15, 10, 30);
        LocalDateTime copy = LocalDateTime.of(2026, 3, 15, 10, 30);
        LocalDateTime tiny = a.plusNanos(1);

        System.out.println("a after a:         " + a.isAfter(a));
        System.out.println("a after copy:      " + a.isAfter(copy));
        System.out.println("tiny after a:      " + tiny.isAfter(a));
        System.out.println("a or later (copy): " + !a.isBefore(copy));
    }
}

How It Works

  1. An object is not after itself. The first line prints false.
  2. An equal copy is not after either. The same moment is neither earlier nor later.
  3. One nanosecond is enough. tiny is slightly later, so the third line prints true.
  4. For "later or the same". Use !a.isBefore(copy), which prints true for equal values.

Example 3 — Show Only Upcoming Events

Go through a list of events and print only those that are after the current moment.

Java
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

public class LdtIsAfterFilter {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.of(2026, 3, 15, 12, 0);
        List<LocalDateTime> events = Arrays.asList(
            LocalDateTime.of(2026, 3, 15, 9, 0),
            LocalDateTime.of(2026, 3, 15, 15, 30),
            LocalDateTime.of(2026, 3, 14, 20, 0),
            LocalDateTime.of(2026, 3, 20, 8, 45)
        );

        for (LocalDateTime event : events) {
            if (event.isAfter(now)) {
                System.out.println("upcoming: " + event);
            }
        }
    }
}

How It Works

  1. A fixed "now". The code uses 12:00 on 15 March so the output never changes.
  2. Test each event. event.isAfter(now) is true only for events in the future.
  3. Past events are skipped. 09:00 today and 20:00 yesterday are before 12:00.
  4. The rest are printed. 15:30 today and 08:45 on the 20th are upcoming, in list order.

Frequently Asked Questions

Use a.isAfter(b). It returns true only if a is later than b.
Use dt.isAfter(LocalDateTime.now()).
No. Equal date-times are neither before nor after each other. Use !a.isBefore(b) for "later or the same".
They give the same answer. isAfter() is easier to read.
No. Both sides must be date-times. Use dt.toLocalDate().isAfter(date), or convert the date with atStartOfDay().

Next: isBefore()

Check if this date-time is earlier than another.

isBefore() 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.

8 people found this page helpful