Javatime-localdate-with
提供:Dev Guides
java.time.LocalDate.with()メソッドの例
説明
- 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.finddevguides;
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