This method returns a copy of this period with the specified amount of years.
package com.logicbig.example.period;
import java.time.Period;
public class WithYearsExample {
public static void main(String... args) {
Period p = Period.of(10, 2, 13);
System.out.println(p);
Period p2 = p.withYears(200);
System.out.println(p2);
Period p3 = p.withYears(-200);
System.out.println(p3);
}
}
Output
P10Y2M13D
P200Y2M13D
P-200Y2M13D