Java Calendar.before(Object when)

Syntax

Calendar.before(Object when) has the following syntax.

public boolean before(Object when)

Example

In the following code shows how to use Calendar.before(Object when) method.


/*from   ww w  . jav a 2s .  c  om*/
import java.util.Calendar;

public class Main {

   public static void main(String[] args) {

      Calendar cal = Calendar.getInstance();
      Calendar past = Calendar.getInstance();

      System.out.println("Current date: " + cal.getTime());

      // change year in past calendar
      past.set(Calendar.YEAR, 2013);
      System.out.println("Year is " + past.get(Calendar.YEAR));

      // check if calendar date is before current date
      System.out.println(cal.before(past));
   }
}