java.time.YearMonth.plus(long amountToAdd,TemporalUnit unit)
方法返回此年月的副本,並添加了指定的數量。
聲明
以下是java.time.YearMonth.plus(long amountToAdd,TemporalUnit unit)
方法的聲明。
public YearMonth plus(long amountToAdd, TemporalUnit unit)
參數
amountToAdd
- 要添加到結果中的單位數量可能為負數。unit
- 要添加總數的單位,而不是null
。
返回值
基於此日期的YearMonth
,添加了指定的總數,而不是null
。
例外
DateTimeException
- 如果無法添加。UnsupportedTemporalTypeException
- 如果不支持該單位。ArithmeticException
- 如果發生數字溢出。
示例
以下示例顯示了java.time.YearMonth.plus(long amountToAdd,TemporalUnit unit)
方法的用法。
package com.zaixian;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
public class YearMonthDemo {
public static void main(String[] args) {
YearMonth date = YearMonth.parse("2017-12");
YearMonth date1 = date.plus(10, ChronoUnit.YEARS);
System.out.println(date1);
}
}
編譯並運行上面的程式,這將產生以下結果 -
2027-12
上一篇:
java.time.YearMonth類
下一篇:
java.time.ZonedDateTime類