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類