- 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.LocalDate.plusYears() 方法示例
說明
java.time.LocalDate.plusYears(long yearsToAdd) 方法返回一個添加了指定年份的本日期的副本。
宣告
以下是 java.time.LocalDate.plusYears(long yearsToAdd) 方法的宣告。
public LocalDate plusYears(long yearsToAdd)
引數
yearsToAdd - 要新增的年數,可以為負數。
返回值
基於該日期並添加了年數的 LocalDate,不為 null。
異常情況
DateTimeException - 如果結果超出了受支援的日期範圍。
示例
以下示例演示了 java.time.LocalDate.plusYears(long yearsToAdd) 方法的使用。
package com.tutorialspoint;
import java.time.LocalDate;
public class LocalDateDemo {
public static void main(String[] args) {
LocalDate date = LocalDate.parse("2017-02-03");
System.out.println(date.plusYears(2));
}
}
讓我們編譯並執行以上程式,它將產生以下結果 -
2019-02-03
廣告