java date add one day

java

To add a day to a java.time.LocalDate object, you can use the plusDays() method.

Here’s an example:

import java.time.LocalDate;

public class Main {
    public static void main(String[] args) {
        LocalDate date = LocalDate.now();
        System.out.println("Current date: " + date);

        // Add 1 day to the current date
        LocalDate nextDay = date.plusDays(1);
        System.out.println("Next day: " + nextDay);
    }
}

You can also use the plus() method with a java.time.Period object to add a specific number of days, months, and years:

import java.time.LocalDate;
import java.time.Period;

public class Main {
    public static void main(String[] args) {
        LocalDate date = LocalDate.now();
        System.out.println("Current date: " + date);

        // Add 1 day, 2 months, and 3 years to the current date
        LocalDate future = date.plus(Period.of(3, 2, 1));
        System.out.println("Future date: " + future);
    }
}