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
廣告
© . All rights reserved.