Friday, September 5, 2025
HomeLanguagesJavaLocalDate plusDays() Method in Java with Examples

LocalDate plusDays() Method in Java with Examples

The plusDays() method of a LocalDate class in Java is used to add the number of specified day in this LocalDate and return a copy of LocalDate. For example, 2018-12-31 plus one day would result in 2019-01-01. This instance is immutable and unaffected by this method call.

Syntax:

public LocalDate plusDays(long daysToAdd)

Parameters: This method accepts a single parameter daysToAdd which represents the days to add, may be negative.

Return Value: This method returns a LocalDate based on this date with the days added, not null.

Exception: This method throws DateTimeException if the result exceeds the supported date range.

Below programs illustrate the plusDays() method:

Program 1:




// Java program to demonstrate
// LocalDate.plusDays() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a LocalDate object
        LocalDate date
            = LocalDate.parse("2018-11-13");
  
        // print instance
        System.out.println("LocalDate before"
                           + " adding days: " + date);
  
        // add 5 days
        LocalDate returnvalue
            = date.plusDays(5);
  
        // print result
        System.out.println("LocalDate after "
                           + " adding days: " + returnvalue);
    }
}


Output:

LocalDate before adding days: 2018-11-13
LocalDate after  adding days: 2018-11-18

Program 2:




// Java program to demonstrate
// LocalDate.plusDays() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a LocalDate object
        LocalDate date
            = LocalDate.parse("2018-12-24");
  
        // print instance
        System.out.println("LocalDate before"
                           + " adding days: " + date);
  
        // add 15 days
        LocalDate returnvalue
            = date.plusDays(15);
  
        // print result
        System.out.println("LocalDate after "
                           + " adding days: " + returnvalue);
    }
}


Output:

LocalDate before adding days: 2018-12-24
LocalDate after  adding days: 2019-01-08

Reference:
https://docs.oracle.com/javase/10/docs/api/java/time/LocalDate.html#plusDays(long)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11861 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6699 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS