获取一天中剩余的时间(秒数)

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);
    }

}
`
posted @ 2022-10-10 11:35  天门道人  阅读(165)  评论(0编辑  收藏  举报