Before Method in Java Calendar To Compare Date and Time in Java

import java.util.Calendar;
public classBeforeMethod {
  public static void main(String[] args) {
    //create first Calendar object
    Calendar old = Calendar.getInstance();
    //set it to some old date
    old.set(Calendar.YEAR, 1990);
    //create second Calendar object
    Calendar now = Calendar.getInstance();
     * To compare two different Calendar objects, use
     * boolean before(Caledar anotherCal) method.
     * If the first Calendar object's date and time is before
     * anotherCal date and time,
     * it returns true, false otherwise.
     System.out.println("Is old before now ? : " + old.before(now));