public static void main(String ... args) { LocalDateTime localDateTime = LocalDateTime.now();
//localDateTime轉字符串
String str = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(localDateTime);
// 字符串轉localDateTime
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime localDateTimeTemp = LocalDateTime.parse("2020-10-10 11:11:11", df);
// 本年本月最后一天
System.out.println(localDateTime.with(TemporalAdjusters.lastDayOfMonth()));
// 本年本月第一天
System.out.println(localDateTime.with(TemporalAdjusters.firstDayOfMonth()));
// 本年下一月第一天
System.out.println(localDateTime.with(TemporalAdjusters.firstDayOfNextMonth()));
// 下一年第一天
System.out.println(localDateTime.with(TemporalAdjusters.firstDayOfNextYear()));
// 本年最后一天
System.out.println(localDateTime.with(TemporalAdjusters.lastDayOfYear()));
// 下一個周五
System.out.println(localDateTime.with(TemporalAdjusters.next(DayOfWeek.FRIDAY)));
// 本月第一個周五
System.out.println(localDateTime.with(TemporalAdjusters.firstInMonth(DayOfWeek.FRIDAY)));
// 本月最后一個周五
System.out.println(localDateTime.with(TemporalAdjusters.lastInMonth(DayOfWeek.FRIDAY)));
// 下一個周五,如果當前是周五則返回當前時間
System.out.println(localDateTime.with(TemporalAdjusters.nextOrSame(DayOfWeek.FRIDAY)));
// 前一個周五
System.out.println(localDateTime.with(TemporalAdjusters.previous(DayOfWeek.FRIDAY)));
// 前一個周五,如果當前是周五則返回當前時間
System.out.println(localDateTime.with(TemporalAdjusters.previousOrSame(DayOfWeek.FRIDAY)));
// 當前時間+100天,plusYeas/plusMonths/plusWeeks/plusHours/plusMinutes/plusSeconds形式相同,同於System.out.println(localDateTime.plus(100, ChronoUnit.DAYS));
System.out.println(localDateTime.plusDays(100));
// 當前時間-100天,minusYeas/minusMonths/minusWeeks/minusHours/minusMinutes/minusSeconds形式相同,同於System.out.println(localDateTime.minus(100, ChronoUnit.DAYS));
System.out.println(localDateTime.minusDays(100));