Java当中得到当前时间距离第二天凌晨还剩多少秒的统一写法

Java当中得到当前时间距离第二天凌晨还剩多少秒的统一写法,第1张

Java当中得到当前时间距离第二天凌晨还剩多少秒的统一写法
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;
    }

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4018532.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-10-22
下一篇2022-10-22

发表评论

登录后才能评论

评论列表(0条)

    保存