java.time.YearMonth.adjustInto(Temporal temporal)方法

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

声明

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

public Temporal adjustInto(Temporal temporal)

参数

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

返回值

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

异常

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

示例

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

package com.zaixian;

import java.time.LocalDate;
import java.time.YearMonth;

public class YearMonthDemo {
   public static void main(String[] args) {

      YearMonth year = YearMonth.of(2015,12);

      LocalDate date = LocalDate.now();
      System.out.println(date);  

      date = (LocalDate)year.adjustInto(date);
      System.out.println(date);  
   }
}

编译并运行上面的程序,这将产生以下结果 -

2017-03-27
2015-12-27

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