Calendar class compareTo(Calendar anotherCalendar) method example
Calendar class compareTo(Calendar anotherCalendar) method example. This example shows you how to use compareTo(Calendar anotherCalendar) method.This method Compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.
Here is the code:-
/**
* @Program that Compares the time values represented by two Calendar objects.
* comparetocalender.java
* Author:-RoseIndia Team
* Date:-22-May-2008
*/
import java.util.*;
public class comparetocalender {
public static void main(String[] args) {
//Creating a calender
Calendar c = new GregorianCalendar(2006, 04, 25);
Calendar c1 = new GregorianCalendar(2007, 04, 25);
// Compares the time values represented by two Calendar objects.
int i = c.compareTo(c1);
//returns positive value if equals else return negative value
System.out.println(i);
}
} |
Output of the program:-
| Calendar objects are equal/not:-1 |
|