The before() method is used to check if a given date is before another given date.
Package: java.util
Java Platform: Java SE 8
Syntax:
before(Date dt)
Parameters:
Name Description dt a dateReturn Value:
true if and only if the instant of time represented by this Date object is strictly earlier than the instant represented by when; false otherwise.
Return Value Type: boolean
Throws:
NullPointerException - if when is null.
Pictorial Presentation of Jave Date before() method:
Example: Java Date.before() Method
The following example fills a Date before(Date when) .
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 before dt2
boolean result = dt1.before(dt2);
System.out.println("Date1 is before date2: " + result);
// Check if dt2 is after dt1
result = dt2.before(dt1);
System.out.println("Date2 is before date1: " + result);
}
}
Output:
Date1 is before date2: true Date2 is before date1: false
Example of Throws: before(Date when) Method
NullPointerException - if when is null.
Java Code Editor:
Previous:after Method
Next:clone Method
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4