- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 瞬時
- java.time - 本地日期
- java.time - 本地日期時間
- java.time - 本地時間
- java.time - 月份日
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 週期
- java.time - 年份
- java.time - 年份月
- java.time - 區域日期時間
- java.time - 區域 ID
- java.time - 區域偏移量
- java.time 包列舉
- java.time - 月份
- java.time 有用資源
- java.time - 討論
java.time.YearMonth.plusYears() 方法示例
描述
java.time.YearMonth.plusYears(long years) 方法返回一個年份增加指定數量的副本本 YearMonth。
宣告
以下是 java.time.YearMonth.plusYears(long years) 方法的宣告。
public YearMonth plusYears(long years)
引數
years − 要新增的年份,可以是正數或負數。
返回值
一個基於此 YearMonth,且年份增加了指定數量的 YearMonth,非空。
異常
ArithmeticException − 如果出現數值溢位。
示例
以下示例演示瞭如何使用 java.time.YearMonth.plusYears(long years) 方法。
package com.tutorialspoint;
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
廣告