Java Utility Library

Java Calendar - after() Method



The java.util.Calendar.after() method is used to test if this Calendar represents a time after the time represented by the specified Object.

Syntax

public boolean after(Object when)

Parameters

when Specify the Object to be compared.

Return Value

Returns true if the time of this Calendar is after the time represented by when; false otherwise.

Exception

NA.

Example:

In the example below, the java.util.Calendar.after() method is used to check whether the time of the given Calendar is after the time represented by the specified Object.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating Calendars
    Calendar Cal1 = new GregorianCalendar(98, 10, 25);
    Calendar Cal2 = new GregorianCalendar(99, 10, 25);
    Calendar Cal3 = new GregorianCalendar(97, 10, 25);

    //checking Cal1 is after Cal2
    System.out.println("Cal1 is after Cal2: " + Cal1.after(Cal2));

    //checking Cal1 is after Cal3
    System.out.println("Cal1 is after Cal3: " + Cal1.after(Cal3));
  }
}

The output of the above code will be:

Cal1 is after Cal2: false
Cal1 is after Cal3: true

❮ Java.util - Calendar