Java Program To Add Days To Date

Chapter: Date and Time Last Updated: 16-04-2023 12:13:32 UTC


            /* ............... START ............... */
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class AddDaysToDate {
    public static void main(String[] args) {
        // Input date in string format
        String inputDate = "2023-04-16";
        // Number of days to add
        int daysToAdd = 10;

        // Create a LocalDate object from the input date string
        LocalDate date = LocalDate.parse(inputDate);

        // Add the number of days to the date
        LocalDate newDate = date.plusDays(daysToAdd);

        // Format the new date as a string using the ISO date format
        String outputDate = newDate.format(DateTimeFormatter.ISO_DATE);

        // Print the new date
        System.out.println("New date: " + outputDate);

                /* ............... END ............... */


New date: 2023-04-26
We have added 10 days to the input date of April 16, 2023, resulting in April 26, 2023.


  • The first step in the program is to define the input date and the number of days to add as strings and an integer, respectively. We then use the LocalDate.parse() method to convert the input date string into a LocalDate object.
  • Once we have a LocalDate object representing the input date, we use the plusDays() method to add the specified number of days to it. This method returns a new LocalDate object representing the updated date.
  • Finally, we format the new date as a string using the ISO date format and print it to the console using the System.out.println() method.
  • Overall, this program demonstrates how to use the LocalDate class from the java.time package to perform date arithmetic in Java.


Java Program To Add Days To Date #How to add days to date in java

Similar Programs Chapter Last Updated
Java Date Format AM PM Date and Time 14-05-2023
Java Add Months To Date Date and Time 14-05-2023
Add Days To Date In Java example Date and Time 14-05-2023
Java Program To Calculate Days Between Two Dates Date and Time 16-04-2023
How To Find Difference Between Two Dates In Java Date and Time 01-04-2023
Add Days To Date Java Example Date and Time 08-08-2021
Time Difference Between Two Timestamps In Java Date and Time 22-09-2018