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



描述

java.time.YearMonth.with(TemporalAdjuster adjuster) 方法返回此年份的一個調整後的副本。

宣告

以下是 java.time.YearMonth.with(TemporalAdjuster adjuster) 方法的宣告。

public YearMonth with(TemporalAdjuster adjuster)

引數

adjuster - 要使用的調整程式,不能為空。

返回值

a YearMonth 基於此月份,已進行調整,不能為空。

異常

  • DateTimeException - 如果無法進行調整。

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

示例

以下示例演示了 java.time.YearMonth.with(TemporalAdjuster adjuster) 方法的用法。

package com.tutorialspoint;

import java.time.YearMonth;

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

      YearMonth date = YearMonth.parse("2017-12");
      YearMonth result = date.with(YearMonth.of(2010,12));
      System.out.println(result);  
   }
}

讓我們編譯並執行以上程式,這將產生以下結果 -

2010-12
廣告
© . All rights reserved.