Close

Java Date Time - LocalDate.plusWeeks() Examples

Java Date Time Java Java API 


Class:

java.time.LocalDate

java.lang.Objectjava.lang.Objectjava.time.LocalDatejava.time.LocalDatejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.time.chrono.ChronoLocalDateChronoLocalDatejava.io.SerializableSerializableLogicBig

Method:

public LocalDate plusWeeks(long weeksToAdd)

This method returns a new instance of LocalDate by adding the specified amount in weeks to the days field adjusting other fields if necessary. The original instance is not changed.

The provided weeksToAdd may be negative, in that case weeks will be subtracted

This method will throw DateTimeException if the result exceeds the supported date range.


Examples


package com.logicbig.example.localdate;

import java.time.LocalDate;

public class PlusWeeksExample {

public static void main (String... args) {

LocalDate d = LocalDate.of(2001, 11, 22);
LocalDate d2 = d.plusWeeks(300);
System.out.println(d2);

LocalDate d3 = d.plusWeeks(-300);
System.out.println(d3);
}
}

Output

2007-08-23
1996-02-22




See Also