Close

Java Date Time - LocalDate.plusMonths() 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 plusMonths(long monthsToAdd)

This method returns a new instance of local date by adding the specified amount to the month field adjusting other fields if necessary. The original instance is not changed.

The provided monthsToAdd can be negative, in that case months 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 PlusMonthsExample {

public static void main (String... args) {
LocalDate d = LocalDate.of(2001, 11, 22);
LocalDate d2 = d.plusMonths(10);
System.out.println(d2);

LocalDate d3 = d.plusMonths(20);
System.out.println(d3);

LocalDate d4 = d.plusMonths(-20);
System.out.println(d4);
}
}

Output

2002-09-22
2003-07-22
2000-03-22




See Also