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

java.time.MonthDay.adjustInto(Temporal temporal)方法将指定的时间对象调整为具有此月-日

声明

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

public Temporal adjustInto(Temporal temporal)

参数

temporal - 要调整的目标对象,不能为null

返回值

调整后的对象,不能为null

异常

  • DateTimeException - 如果无法进行调整。
  • ArithmeticException - 如果发生数字溢出。

示例

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

package com.zaixian;

import java.time.MonthDay;
import java.time.ZonedDateTime;

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

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

      MonthDay date1 = MonthDay.parse("--12-30");
      date = (ZonedDateTime)date1.adjustInto(date);
      System.out.println(date);  
   }
}

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

2017-03-20T15:29:58.470+05:30[Asia/Calcutta]
2017-12-30T15:29:58.470+05:30[Asia/Calcutta]

上一篇: java.time.MonthDay类 下一篇: java.time.OffsetDateTime类