java.time.Year.adjustInto() 方法

描述

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


声明

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

public Temporal adjustInto(Temporal temporal)

参数

temporal − 要调整的时间对象,不为空。


返回值

调整后的同一类型的对象,不为空。


异常

  • DateTimeException − 如果无法添加。

  • ArithmeticException − 如果发生数字溢出。


示例

下面的例子展示了 java.time.Year.adjustInto(Temporal 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