- java.time 包類
- java.time - 主頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - 週期
- java.time - 年
- java.time - 年月
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 程式包列舉
- java.time - 月
- java.time 有用資源
- java.time - 討論
java.time.Period.plusYears() 方法示例
描述
返回帶有指定年數的此 Period 的副本。
宣告
以下是 java.time.Period.plusYears(long years) 方法的宣告。
public Period plusYears(long years)
引數
years - 要新增的年數,正數或負數。
返回值
基於此 Period 且添加了指定年數的 Period,非空。
異常
算術異常 - 如果出現數值溢位。
示例
以下示例演示了 java.time.Period.plusYears(long years) 方法的用法。
package com.tutorialspoint;
import java.time.Period;
public class PeriodDemo {
public static void main(String[] args) {
Period period = Period.ofYears(2);
Period period1 = period.plusYears(1);
System.out.println(period1.getYears());
}
}
讓我們編譯並執行以上程式,它會生成以下結果 -
3
廣告