Java Date Time - Java Calendar.after(Object when)








Syntax

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

public boolean after(Object when)

Example

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

//from   w ww  .  j a v a2 s. c o m
import java.util.Calendar;
import java.util.Date;

public class Main {

   public static void main(String[] args) {
   
      Calendar cal = Calendar.getInstance();
      Calendar future = Calendar.getInstance();

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

      future.set(Calendar.YEAR, 2015);
      System.out.println("Year is " + future.get(Calendar.YEAR));

      Date time = future.getTime();
      if (future.after(cal)) {
         System.out.println("Date " + time + " is after current date.");
      }

   }
}

The code above generates the following result.