The before() method of Java Date class tests whether the date is before the specified date or not.
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:
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
Date 1: Wed Jan 02 08:15:06 UTC 2019 Date 1: null On checking these 2 dates: Exception: java.lang.NullPointerException
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java SQL Timestamp before() function with examples
- Date compareTo() method in Java with examples
- Date equals() method in Java with Examples
- Date toString() method in Java with Examples
- Date hashCode() method in Java with Examples
- Date setTime() method in Java with Examples
- Date getTime() method in Java with Examples
- Date toInstant() Method in Java with Examples
- Date clone() method in Java with Examples
- Date from() method in Java with Examples
- LocalDateTime of(date, time) method in Java with Examples
- Date class in Java (With Examples)
- util.date class methods in Java with Examples
- Date after() method in Java
- DateFormat format(Date obj) method in Java
- HijrahChronology date() method in Java with Example : Set - 1
- HijrahChronology date() method in Java with Example : Set - 2
- IsoChronology date(int, int, int) method in Java with Example
- IsoChronology date(TemporalAccessor) method in Java with Example
- JapaneseChronology date(int, int, int) method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.