java date add days

java

In Java, you can use the plusDays method of the LocalDate class to add a certain number of days to a LocalDate object.

Here’s an example of how you can use the plusDays method to add days to a LocalDate object:

import java.time.LocalDate;

public class Main {
  public static void main(String[] args) {
    // Create a LocalDate object for the current date
    LocalDate date = LocalDate.now();
    System.out.println(date);  // Outputs something like "2022-07-03"
    
    // Add 10 days to the LocalDate
    LocalDate newDate = date.plusDays(10);
    System.out.println(newDate);  // Outputs something like "2022-07-13"
  }
}

This code will create a LocalDate object for the current date, and then add 10 days to it, producing a new LocalDate object representing a date 10 days in the future.

Note that the LocalDate class is part of the new java.time package introduced in Java 8. If you are using an older version of Java that does not have the java.time package, you can use the Calendar class from the java.util package to add days to a Date object.