Java Date.after(Date when)

Syntax

Date.after(Date when) has the following syntax.

public boolean after(Date when)

Example

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


import java.util.Calendar;
import java.util.Date;
//w w  w  . ja  v a2 s. c o m
public class Main {
  public static void main(String[] args) {
    Date d1 = Calendar.getInstance().getTime();

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2000);
    Date d2 = cal.getTime();
    
    System.out.println("First Date : " + d1);
    System.out.println("Second Date : " + d2);
    System.out.println("Is second date after first ? : " + d2.after(d1));
  }
}

The output: