LAST UPDATED: NOVEMBER 27, 2020
Java LocalDate plusWeeks() Method
Java plusWeeks() method is used to plus the specified number of weeks to a date. It adds the weeks and returns a new LocalDate
. For example, 2009-10-10 plus one week would result in 2009-10-17.
It takes a long type argument that represents the number of weeks and returns a new LocalDate
. The syntax of the method is given below.
Syntax
public LocalDate plusWeeks(long weeksToAdd)
Parameters:
It takes a parameter of long type that represents the number of weeks.
Returns:
It returns a local-date after adding the specified weeks to a date.
Time for an Example:
Let's take an example to add weeks to a date. Here, we are adding 2 weeks by using the plusWeeks()
method that returns a new local-date. See the below example.
import java.time.LocalDate;
public class DateDemo {
public static void main(String[] args){
LocalDate localDate = LocalDate.of(2016, 10, 21);
System.out.println(localDate);
localDate = localDate.plusWeeks(2);
System.out.println("New date : "+localDate);
}
}
2016-10-21
New date : 2016-11-04
Time for another Example:
Let's take another example to understand the plusWeeks()
method. Here, we are adding 5 weeks to the current date. See the example below.
import java.time.LocalDate;
public class DateDemo {
public static void main(String[] args){
LocalDate localDate = LocalDate.now();
System.out.println(localDate);
localDate = localDate.plusWeeks(5);
System.out.println("New date : "+localDate);
}
}
2020-06-17
New date : 2020-07-22
Live Example:
Try with a live example, execute the code instantly with our powerful Online Java Compiler.