- 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 until() Method in Java
The difference between two LocalDate objects can be obtained using the until() method in the LocalDate class in Java. This method requires a single parameter i.e. the end date for the LocalDate object and it returns the difference between two LocalDate objects using a Period object.
A program that demonstrates this is given as follows:
Example
import java.time.*; public class Demo { public static void main(String[] args) { LocalDate ld1 = LocalDate.parse("2019-01-10"); LocalDate ld2 = LocalDate.parse("2019-02-14"); System.out.println("The first LocalDate is: " + ld1); System.out.println("The second LocalDate is: " + ld2); System.out.println("The difference between two LocalDates is: " + ld1.until(ld2)); } }
Output
The first LocalDate is: 2019-01-10 The second LocalDate is: 2019-02-14 The difference between two LocalDates is: P1M4D
Now let us understand the above program.
First the two LocalDate objects are displayed. Then the difference between them is obtained using the until() method and displayed. A code snippet that demonstrates this is as follows:
LocalDate ld1 = LocalDate.parse("2019-01-10"); LocalDate ld2 = LocalDate.parse("2019-02-14"); System.out.println("The first LocalDate is: " + ld1); System.out.println("The second LocalDate is: " + ld2); System.out.println("The difference between two LocalDates is: " + ld1.until(ld2));
Advertisements