Java Instant.isAfter() Method with Examples

Tags: Java Instant Java 8

In this Java core tutorial we learn how to use the java.time.Instant.isAfter() method to check if an Instant object is after another Instant object or not in Java programming language.

How to use Instant.isAfter() method

In Java, to check if an Instant object is after another Instant object or not we can use the Instant.isAfter(Instant otherInstant) method as Java code below.

InstantIsAfterExample1.java

import java.time.Instant;

public class InstantIsAfterExample1 {
    public static void main(String... args) {
        Instant instant1 = Instant.parse("2022-07-12T08:00:30Z");
        Instant instant2 = Instant.parse("2022-07-11T08:00:30Z");
        Instant instant3 = Instant.parse("2022-07-15T08:00:30Z");

        boolean result1 = instant1.isAfter(instant2);
        boolean result2 = instant1.isAfter(instant3);

        System.out.println("instant1: " + instant1);
        System.out.println("instant2: " + instant2);
        System.out.println("instant3: " + instant3);
        System.out.println("instant1 is after instant2: " + result1);
        System.out.println("instant1 is after instant3: " + result2);
    }
}
The output as below.
instant1: 2022-07-12T08:00:30Z
instant2: 2022-07-11T08:00:30Z
instant3: 2022-07-15T08:00:30Z
instant1 is after instant2: true
instant1 is after instant3: false

Happy Coding 😊

Java Instant.now() Method with Examples

Java Instant.ofEpochSecond() Method with Examples

Java Instant.ofEpochMilli() Method with Examples

Java Instant.parse() Method with Examples

Java Instant.getEpochSecond() Method with Examples

Java Instant.getNano() Method with Examples

Java Instant.plusSeconds() Method with Examples

Java Instant.plusMillis() Method with Examples

Java Instant.plusNanos() Method with Examples

Java Instant.minusSeconds() Method with Examples

Java Instant.minusMillis() Method with Examples

Java Instant.minusNanos() Method with Examples

Java Instant.atOffset() Method with Examples

Java Instant.atZone() Method with Examples

Java Instant.toEpochMilli() Method with Examples

Java Instant.compareTo() Method with Examples

Java Instant.isBefore() Method with Examples

Java Instant.equals() Method with Examples

Java Instant.toString() Method with Examples

Java Compare two Instant Values