java.time.Year.adjustInto()方法

java.time.Year.adjustInto(Temporal temporal)方法將指定的時態對象調整為今年。

聲明

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

public Temporal adjustInto(Temporal temporal)

參數

  • temporal - 要調整的時間對象,而不是null

返回值
進行調整的相同類型的對象,不為null

異常

  • DateTimeException - 如果無法添加。
  • ArithmeticException - 如果發生數字溢出。

示例

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

package com.zaixian;

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

上一篇: java.time.Year類 下一篇: java.time.YearMonth類