読者です 読者をやめる 読者になる 読者になる

LocalDateTime 使い方

java

現在時刻の取得

LocalDateTime now = LocalDateTime.now();
System.out.println(now);




月の追加

LocalDateTime addMonths = now.plus(3, ChronoUnit.MONTHS);
System.out.println(addMonths);




フォーマッター

DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy/MM/dd");

LocalDateTime now = LocalDateTime.now();
String today = now.format(format);
System.out.println(today);




差分(日数)

int dayDiff = (int) ChronoUnit.DAYS.between(now, addMonths);
System.out.println(dayDiff);