Java Date - after() Method
The java.util.Date.after() method is used to test if this date is after the specified date or not. The method returns true if this Date object is strictly later than the specified Date object, else returns false.
Syntax
public boolean after(Date when)
Parameters
when |
Specify a date. |
Return Value
Returns true if this Date object is strictly later than the when Date object; false otherwise.
Exception
Throws NullPointerException, if when is null.
Example:
In the example below, the java.util.Date.after() method is used to check whether the given Date is after the specified date or not.
import java.util.*; public class MyClass { public static void main(String[] args) { //creating Dates Date Dt1 = new Date(1000); Date Dt2 = new Date(); Date Dt3 = new Date(2000); //checking Dt1 is after Dt2 System.out.println("Dt1 is after Dt2: " + Dt1.after(Dt2)); //checking Dt1 is after Dt3 System.out.println("Dt1 is after Dt3: " + Dt1.after(Dt3)); } }
The output of the above code will be:
Dt1 is after Dt2: false Dt1 is after Dt3: true
❮ Java.util - Date