java.time.Year.adjustInto()方法

java.time.Year.adjustInto(Temporal temporal)方法将指定的时态对象调整为今年。

声明

以下是java.time.Year.adjustInto(Temporal temporal)方法的声明。

public Temporal adjustInto(Temporal temporal)

参数

  • temporal - 要调整的时间对象,而不是null

返回值
进行调整的相同类型的对象,不为null

异常

  • DateTimeException - 如果无法添加。
  • ArithmeticException - 如果发生数字溢出。

示例

以下示例显示了java.time.Year.adjustInto(Temporal temporal)方法的用法。

package com.zaixian;

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

上一篇: java.time.Year类 下一篇: java.time.YearMonth类