Compare two Calendar values
boolean after(Object when)
- Returns whether this Calendar represents a time after the time represented by the specified Object.
boolean before(Object when)
- Returns whether this Calendar represents a time before the time represented by the specified Object.
int compareTo(Calendar anotherCalendar)
- Compares the time values (millisecond offsets from the Epoch) represented by two Calendar objects.
boolean equals(Object obj)
- Compares this Calendar to the specified Object.
Compare date time using after method
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar future = Calendar.getInstance();
future.set(Calendar.YEAR, 3010);
Calendar now = Calendar.getInstance();
System.out.println("Is futureCal after now ? : " + future.after(now));
}
}
The output:
Is futureCal after now ? : true
Compare date time using before method
import java.util.Calendar;
public class Main {
public static void main(String[] args) {
Calendar old = Calendar.getInstance();
old.set(Calendar.YEAR, 1990);
Calendar now = Calendar.getInstance();
System.out.println("Is old before now ? : " + old.before(now));
}
}
The output:
Is old before now ? : true