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
广告
© . All rights reserved.