This method returns a copy of this period with the specified amount of months.
package com.logicbig.example.period;
import java.time.Period;
public class WithMonthsExample {
public static void main(String... args) {
Period p = Period.of(10, 2, 13);
System.out.println(p);
Period p2 = p.withMonths(10);
System.out.println(p2);
Period p3 = p.withMonths(-100);
System.out.println(p3);
Period p4 = p3.normalized();
System.out.println(p4);
}
}
Output
P10Y2M13D
P10Y10M13D
P10Y-100M13D
P1Y8M13D