Date date = new Date();
//使用plusDays加传入的时间加1天,将时分秒设置成0
LocalDateTime midnight = LocalDateTime.ofInstant(date.toInstant(),
ZoneId.systemDefault()).plusDays(1).withHour(0).withMinute(0)
.withSecond(0).withNano(0);
LocalDateTime currentDateTime = LocalDateTime.ofInstant(date.toInstant(),
ZoneId.systemDefault());
//使用ChronoUnit.SECONDS.between方法,传入两个LocalDateTime对象即可得到相差的秒数
long seconds = ChronoUnit.SECONDS.between(currentDateTime, midnight);
System.out.println(seconds);
java 计算当天剩余多少秒
最新推荐文章于 2023-06-20 11:08:39 发布