- java.time 包類
- java.time - 首頁
- java.time - 時鐘
- java.time - 持續時間
- java.time - 即時時間
- java.time - 本地日期
- java.time - 本地日期時間
- java.time - 本地時間
- java.time - 月份天數
- java.time - 偏移日期時間
- java.time - 偏移時間
- java.time - 週期
- java.time - 年份
- java.time - 年份月份
- java.time - 分割槽日期時間
- java.time - 時區 ID
- java.time - 時區偏移
- java.time 包列舉
- java.time - 月份
- java.time 有用資源
- java.time - 討論
java.time.Year.adjustInto() 方法示例
說明
java.time.Year.adjustInto(Temporal temporal) 方法調整指定的時間物件使之具有當前年份。
宣告
以下是 java.time.Year.adjustInto(TemporalType temporal) 方法的宣告。
public Temporal adjustInto(Temporal temporal)
引數
temporal − 要調整的時間物件,不能為空。
返回值
具有已做調整的相同型別的物件,不能為空。
異常
DateTimeException − 如果無法新增。
ArithmeticException − 如果發生數字溢位。
示例
以下示例展示了 java.time.Year.adjustInto(TemporalType temporal) 方法的用法。
package com.tutorialspoint;
import java.time.LocalDate;
import java.time.Year;
public class YearDemo {
public static void main(String[] args) {
Year year = Year.of(2015);
LocalDate date = LocalDate.now();
System.out.println(date);
date = (LocalDate)year.adjustInto(date);
System.out.println(date);
}
}
讓我們編譯並執行以上程式,這會產生以下結果 −
2017-04-01 2015-04-01
廣告