Open In App

Date before() method in Java with Examples

Last Updated : 02 Jan, 2019
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
The before() method of Java Date class tests whether the date is before the specified date or not. Syntax:
public boolean before(Date when)
Parameters: The function accepts a single parameter when which specifies the date that has to be checked. Return Value: It returns a Boolean value. It will return true if this date is before the specified date otherwise false. Exception: The function throws a single exception that is NullPointerException if when is null. Program below demonstrates the above mentioned function:
Output:
Date 1: Thu Dec 05 08:15:01 UTC 1996
Date 2: Wed Jan 02 08:15:01 UTC 2019
Is Date 2 before Date 1: false
Output:
Date 1: Wed Jan 02 08:15:06 UTC 2019
Date 1: null
On checking these 2 dates: 
Exception: java.lang.NullPointerException

Practice Tags :

Similar Reads