java.time.LocalDate.with(TemporalAdjuster adjuster)
方法返回此日期的調整副本。
聲明
以下是java.time.LocalDate.with(TemporalAdjuster adjuster)
方法的聲明。
public LocalDate with(TemporalAdjuster adjuster)
參數
adjuster
- 要使用的調整器,而不是null
。
返回值
- 基於此的
LocalDate
進行調整,而不是null
。
異常
DateTimeException
- 如果無法進行調整。ArithmeticException
- 如果發生數字溢出。
示例
以下示例顯示了java.time.LocalDate.with(TemporalAdjuster adjuster)
方法的用法。
package com.zaixian;
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
上一篇:
java.time.LocalDate類
下一篇:
java.time.LocalDateTime類