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



說明

java.time.LocalDate.with(TemporalAdjuster adjuster) 方法返回本日期的已調整副本。

宣告

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

public LocalDate with(TemporalAdjuster adjuster)

引數

adjuster − 要使用的調整器,非空。

返回值

基於此日期、已作出調整且非空的 LocalDate。

異常

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

  • ArithmeticException − 如果發生數值溢位。

示例

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

package com.tutorialspoint;

import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;

public class LocalDateDemo {
   public static void main(String[] args) {
      
      LocalDate date = LocalDate.parse("2017-01-03");
      LocalDate result = date.with(Month.JULY).with(TemporalAdjusters.lastDayOfMonth());
      System.out.println(result);  
   }
}

讓我們編譯並執行上述程式,它將產生以下結果 −

2017-07-31
廣告
© . All rights reserved.