- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
LocalDate isBefore() method in Java
It can be checked if a particular LocalDate is before the other LocalDate in a timeline using the isBefore() method in the LocalDate class in Java. This method requires a single parameter i.e. the LocalDate object that is to be compared. It returns true if the LocalDate object is before the other LocalDate object and false otherwise.
A program that demonstrates this is given as follows −
Example
import java.time.*; public class Main { public static void main(String[] args) { LocalDate ld1 = LocalDate.parse("2019-02-12"); LocalDate ld2 = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate ld1 is: " + ld1); System.out.println("The LocalDate ld2 is: " + ld2); boolean flag = ld1.isBefore(ld2); if(flag) System.out.println("
LocalDate object ld1 is before LocalDate object ld2"); else System.out.println("
LocalDate object ld1 is after LocalDate object ld2"); } }
Output
The LocalDate ld1 is: 2019-02-12 The LocalDate ld2 is: 2019-02-14 LocalDate object ld1 is before LocalDate object ld2
Now let us understand the above program.
The two LocalDate objects ld1 and ld2 are displayed. It is checked if the LocalDate object ld1 is before the LocalDate object ld2 in the timeline using the isBefore() method. The returned value is displayed using an if statement. A code snippet that demonstrates this is as follows −
LocalDate ld1 = LocalDate.parse("2019-02-12"); LocalDate ld2 = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate ld1 is: " + ld1); System.out.println("The LocalDate ld2 is: " + ld2); boolean flag = ld1.isBefore(ld2); if(flag) System.out.println("
LocalDate object ld1 is before LocalDate object ld2"); else System.out.println("
LocalDate object ld1 is after LocalDate object ld2");
- Related Articles
- LocalTime isBefore() method in Java
- MonthDay isBefore() Method in Java
- Instant isBefore() method in Java
- LocalDateTime isBefore() method in Java
- LocalDate plusMonths() method in Java
- LocalDate plusWeeks() method in Java
- LocalDate plusDays() Method in Java
- LocalDate plusYears() method in Java
- LocalDate minusDays() Method in Java
- LocalDate minusWeeks() Method in Java
- LocalDate minusMonths() Method in Java
- LocalDate now() Method in Java
- LocalDate query() Method in Java
- LocalDate parse() method in Java
- LocalDate plus() method in Java

Advertisements