java.time.YearMonth.adjustInto() 方法示例



描述

java.time.YearMonth.adjustInto(Temporal temporal) 方法將指定的時間物件調整為該年-月。

宣告

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

public Temporal adjustInto(Temporal temporal)

引數

temporal - 要調整的時間物件(非空)。

返回值

已進行調整的相同型別的物件(非空)。

異常

  • DateTimeException - 如果無法新增。

  • ArithmeticException - 如果發生數字溢位。

示例

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

package com.tutorialspoint;

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
廣告
© . All rights reserved.