java.time.Year.plus(long amountToAdd,TemporalUnit unit)
方法返回指定數量的今年副本。
以下是java.time.Year.plus(long amountToAdd,TemporalUnit unit)
方法的宣告。
public Year plus(long amountToAdd, TemporalUnit unit)
amountToAdd
- 要新增到結果中的單位數量可能為負數。unit
- 要新增的金額的單位,而不是null
。基於此日期的年份,新增了指定的金額,而不是null
。
DateTimeException
- 如果無法新增。UnsupportedTemporalTypeException
- 如果不支援該單位。ArithmeticException
- 如果發生數位溢位。以下範例顯示了java.time.Year.plus(long amountToAdd,TemporalUnit unit)
方法的用法。
package com.yiibai;
import java.time.Year;
import java.time.temporal.ChronoUnit;
public class YearDemo {
public static void main(String[] args) {
Year date = Year.parse("2017");
Year date1 = date.plus(10, ChronoUnit.YEARS);
System.out.println(date1);
}
}
編譯並執行上面的程式,這將產生以下結果 -
2027