Home Java LocalDateTime Methods isAfter() Java LocalDateTime isAfter() Method 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.
LocalDateTime deadline = LocalDateTime.of(2026, 3, 15, 17, 0);
LocalDateTime submitted = LocalDateTime.of(2026, 3, 15, 17, 1);
boolean late = submitted.isAfter(deadline); // true Call What 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.time.LocalDateTime
public boolean isAfter(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 this date-time is later than other, otherwise false.
Important
Equal date-times are not after each other, so a.isAfter(a) is false. If you want "later or the same", write !a.isBefore(b). Passing null throws a NullPointerException. Both date-times are compared as local times, without any time zone.
Compare with Similar Methods Ways to compare date-times:
Java Examples 1. Is it late 2. Equal is not after 3. Upcoming events Example 1 — Check If a Submission Is Late The deadline is 17:00. Check three submission times.
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));
}
} 16:59 late: false
17:01 late: true
next day late: true How It Works A fixed deadline. 17:00 on 15 March 2026.One minute early. 16:59 is not after the deadline, so the answer is false.One minute late. 17:01 is after it, so the answer is true.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.
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));
}
} a after a: false
a after copy: false
tiny after a: true
a or later (copy): true How It Works An object is not after itself. The first line prints false.An equal copy is not after either. The same moment is neither earlier nor later.One nanosecond is enough. tiny is slightly later, so the third line prints true.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.
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);
}
}
}
} upcoming: 2026-03-15T15:30
upcoming: 2026-03-20T08:45 How It Works A fixed "now". The code uses 12:00 on 15 March so the output never changes.Test each event. event.isAfter(now) is true only for events in the future.Past events are skipped. 09:00 today and 20:00 yesterday are before 12:00.The rest are printed. 15:30 today and 08:45 on the 20th are upcoming, in list order.Frequently Asked Questions How do I check if a date is after another date in Java? Use a.isAfter(b). It returns true only if a is later than b.
How do I check if a LocalDateTime is in the future? Use dt.isAfter(LocalDateTime.now()).
Is isAfter() true for equal date-times? No. Equal date-times are neither before nor after each other. Use !a.isBefore(b) for "later or the same".
What is the difference between isAfter() and compareTo() > 0? They give the same answer. isAfter() is easier to read.
Can I compare a LocalDateTime with a LocalDate using isAfter()? No. Both sides must be date-times. Use dt.toLocalDate().isAfter(date), or convert the date with atStartOfDay().
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.
8 people found this page helpful
Helpful Share Copy link Suggestion