LocalDateTime獲取今天最早時刻和最晚時刻

梧桐将秋色發表於2024-09-12

先獲取,再格式化 ;
LocalDateTime of = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
System.out.println( of.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

LocalDateTime max = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
System.out.println(max.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

或者
LocalDateTime.of(LocalDate.now(),LocalTime.of(0,0,0,0))
LocalDateTime.of(LocalDate.now(),LocalTime.of(23,59,59))

相關文章