java.time.Period.plusMonths(long months)
方法返回此Period
的副本,並新增指定的Period
。
以下是java.time.Period.plusMonths(long months)
方法的宣告。
public Period plusMonths(long months)
months
- 新增的月份,正或負值。一個基於此Period
的期間,新增了指定的月份,而不是null
。
ArithmeticException
- 如果發生數位溢位。以下範例顯示了java.time.Period.plusMonths(long months)
方法的用法。
package com.yiibai;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.ofMonths(2);
Period period1 = period.plusMonths(1);
System.out.println(period1.getMonths());
}
}
編譯並執行上面的程式,這將產生以下結果 -
3