- 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
广告