How To Print Future and Past Date using LocalDate in Java | Java Interview Questions

The Java LocalDate class can represent dates, with methods to get today’s date, add/subtract days/weeks/years to calculate future or past dates, and print the results. Manipulating dates is straightforward with LocalDate’s intuitive API.

Here is a 4 line summary of how to print future and past dates using LocalDate in Java:

  1. Import Java time classes: import java.time.LocalDate;
  2. Create LocalDate instance: LocalDate date = LocalDate.now();
  3. Print future/past dates: date = date.plusDays(1); or date = date.minusWeeks(2);
  4. Print result: System.out.println(date);

Java Program

Share

Leave a Reply