Javatime-localdatetime-with
提供:Dev Guides
java.time.LocalDateTime.with()メソッドの例
説明
- java.time.LocalDateTime.with(TemporalAdjuster adjuster)*メソッドは、この日時の調整済みコピーを返します。
宣言
以下は、* java.time.LocalDateTime.with(TemporalAdjuster adjuster)*メソッドの宣言です。
public LocalDateTime with(TemporalAdjuster adjuster)
パラメーター
*adjuster* -使用するアジャスター、null以外。
戻り値
これに基づいて調整が行われたLocalDateTime、null以外
例外
- DateTimeException -調整を行えない場合。
- ArithmeticException -数値オーバーフローが発生した場合。
例
次の例は、java.time.LocalDateTime.with(TemporalAdjuster adjuster)メソッドの使用方法を示しています。
package com.finddevguides;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
public class LocalDateTimeDemo {
public static void main(String[] args) {
LocalDateTime date = LocalDateTime.parse("2017-01-03T10:15:30");
LocalDateTime result = date.with(Month.JULY).with(TemporalAdjusters.lastDayOfMonth());
System.out.println(result);
}
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
2017-07-31T10:15:30