- java.time 包類
- java.time - 首頁
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time 包列舉
- java.time - Month
- java.time 實用資源
- java.time - 討論
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
廣告