Java Date.after() Method
public boolean after(Date dt)
The after() method is used to check if a given date is after another given date.
Package: java.util
Java Platform: Java SE 8
Syntax:
after(Date dt)
Parameters:
Name | Description |
---|---|
dt | a date |
Return Value:
true if and only if the instant represented by this Date object is strictly later than the instant represented by when; false otherwise.
Return Value Type: boolean
Throws:
NullPointerException - if when is null.
Pictorial Presentation of Jave Date after() method:
Example: Java Date.after() Method.
import java.util.*;
public class Main {
public static void main(String[] args) {
// create 2 dates
Date dt1 = new Date(2017, 3, 31);
Date dt2 = new Date(2017, 5, 14);
// Check if dt1 is after dt2
boolean result = dt1.after(dt2);
System.out.println("Date1 is after date2: " + result);
// Check if dt2 is after dt1
result = dt2.after(dt1);
System.out.println("Date2 is after date1: " + result);
}
}
Output:
Date1 is after date2: false Date2 is after date1: true
Java Code Editor:
Previous:Date Class Methods
Home
Next:before Method
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/java-tutorial/util/date/java_date_after.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics