Compare Calendars for before or after in Java
Description
The following code shows how to compare Calendars for before or after.
Example
/*from ww w.j ava 2s .co m*/
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Main {
public static void main(String[] a) {
GregorianCalendar today = new GregorianCalendar();
GregorianCalendar thisDate = new GregorianCalendar();
thisDate.set(Calendar.YEAR, 2000);
if (thisDate.before(today)) {
System.out.println("before");
}
if (today.after(thisDate)) {
System.out.println("after");
}
}
}
The code above generates the following result.