public long get() {
Date currentDate = new Date();
// 明天00:00
LocalDateTime midnight = LocalDateTime.ofInstant(currentDate.toInstant(),
ZoneId.systemDefault()).plusDays(1).withHour(0).withMinute(0)
.withSecond(0).withNano(0);
// 当前时间
LocalDateTime currentDateTime = LocalDateTime.ofInstant(currentDate.toInstant(),
ZoneId.systemDefault());
long result = ChronoUnit.SECONDS.between(currentDateTime, midnight);
return result;
}
Java当中得到当前时间距离第二天凌晨还剩多少秒的统一写法
计算到明天00:00的剩余秒数
最新推荐文章于 2023-04-12 16:55:21 发布
该代码段计算从当前时间到明天00:00的秒数差。它首先获取当前日期,然后转换为LocalDateTime并添加一天,设置时间为00:00。接着,它计算两个LocalDateTime之间的秒数差,并返回结果。

1万+

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



