public class TimeUtil {
/**
* 获取一天中剩余的时间(秒数)
*/
public static Integer getDayRemainingTime() {
Date now = new Date();
LocalDateTime midnight = LocalDateTime.ofInstant(now.toInstant(),
ZoneId.systemDefault()).plusDays(1).withHour(0).withMinute(0)
.withSecond(0).withNano(0);
LocalDateTime currentDateTime = LocalDateTime.ofInstant(now.toInstant(),
ZoneId.systemDefault());
long seconds = ChronoUnit.SECONDS.between(currentDateTime, midnight);
return (int) seconds;
}
public static void main(String[] args) {
Integer seconds = getDayRemainingTime();
System.out.println(seconds / 60 / 60);
}
}
`