Javatpoint Logo
Javatpoint Logo

Java Calendar compareTo() Method

The compareTo() method of Calendar class compares the time values (millisecond offsets) between two calendar object.

Syntax

Parameter

anotherCalendar - the Calendar object to be compared.

Returns

Returns an integer value either 0 , 1 or -1

Throws

NullPointerException - if the specified Calendar is null.

IllegalArgumentException - if the time value of the specified Calendar object can't be obtained

Example 1

Test it Now

Output:

The result is :1

Example 2

Test it Now

Output:

The result is :-1

Example 3

Test it Now

Output:

The result is :0



Help Others, Please Share

facebook twitter pinterest