Java.util.Date.after() Method



The java.util.Date.after(Date when) method checks if this date is after the specified date.


Following is the declaration for java.util.Date.after() method

public boolean after(Date when)


  • when -- date to be checked

Return Value

true if the represented Date object is strictly later than the instant represented by when; false otherwise.


  • NullPointerException -- if when is null.


The following example shows the usage of java.util.Date.after() method.

package com.tutorialspoint;

import java.util.*;

public class DateDemo {

   public static void main(String[] args) {

   // create 2 dates
   Date date = new Date(2011, 5, 21);
   Date date2 = new Date(2015, 1, 21);

   // tests if date 2 is after date and print
   boolean after = date2.after(date);
   System.out.println("Date 2 is after date: " + after);

   // tests if date is after date 2 and print
   after = date.after(date2);
   System.out.println("Date is after date 2: " + after);

Let us compile and run the above program, this will produce the following result:

Date 2 is after date: true
Date is after date 2: false