GregorianCalendar after(Object) in Java

after(Object): This method is available in java.util.GregorianCalendar class of Java.

Syntax:

boolean java.util.Calendar.after(Object when)

This method takes one argument of type Object as its parameter. This method returns whether this Calendar represents a time after the time represented by the specified Object.

Parameters: One parameter is required for this method.

when: the Object to be compared.

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

Exceptions: NA

Approach

Java

import java.util.GregorianCalendar;

public class GregorianCalendarafter {
    public static void main(String[] args) {

        GregorianCalendar cal = (GregorianCalendar)
GregorianCalendar.getInstance();

        GregorianCalendar when = (GregorianCalendar)
GregorianCalendar.getInstance();
        when.add(GregorianCalendar.MONTH, -1);

        System.out.println(cal.after(when));
    }
}

Output:

true


No comments:

Post a Comment