java.time.YearMonth.plusYears(long years)方法返回此YearMonth的副本,并添加了指定的年份。
声明
以下是java.time.YearMonth.plusYears(long years)方法的声明。
public YearMonth plusYears(long years)
参数
years- 添加的年份,正或负值。
返回值
基于此YearMonth添加了指定的年份的YearMonth,而不是null。
例外
ArithmeticException- 如果发生数字溢出。
示例
以下示例显示了java.time.YearMonth.plusYears(long years)方法的用法。
package com.zaixian;
import java.time.YearMonth;
public class YearMonthDemo {
public static void main(String[] args) {
YearMonth date = YearMonth.parse("2017-12");
YearMonth date1 = date.plusYears(10);
System.out.println(date1);
}
}
编译并运行上面的程序,这将产生以下结果 -
2027-12
上一篇:
java.time.YearMonth类
下一篇:
java.time.ZonedDateTime类
