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類