Calendar before(Object) in Java

before(Object): This method is available in java.util.Calendar class of Java.

Syntax:

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

This method takes one argument of type Object as its parameter. This method returns whether this Calendar represents a time before 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 before the time represented by when; false otherwise.

Exceptions: NA

Approach

Java

import java.util.Calendar;

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

        // create a calendar
        Calendar calendar = Calendar.getInstance();
        Calendar when = Calendar.getInstance();
        when.add(Calendar.DATE, 2);
        System.out.println(calendar.before(when));

    }
}

Output:

true


No comments:

Post a Comment