public static void main(String[] args) {
LocalDateTime endTime = LocalDateTime.of(LocalDateTime.now().getYear(),
LocalDateTime.now().getMonth(),
LocalDateTime.now().withDayOfMonth(15).getDayOfMonth(), 23, 59, 59);
Duration dur = Duration.between(endTime, LocalDateTime.now());
long toDays = dur.toDays();
System.out.println(toDays);
}
Duration.between的格式注意下~~~
本文介绍了一个Java程序片段,用于计算当前时间距离本月指定日期(例如15号23:59:59)剩余的天数。通过使用`LocalDateTime`类和`Duration.between`方法实现,有助于理解日期和时间的操作。

被折叠的 条评论
为什么被折叠?



