时间戳毫秒转LocalDateTime

public static void main(String[] args) {
        //时间戳毫秒转LocalDateTime
        LocalDateTime localDateTime = new Date(1535444725000L).toInstant().atOffset(ZoneOffset.of("+8")).toLocalDateTime();

        System.out.println(localDateTime);

        System.out.println(getRemainSecondsOneDay(new Date()));
    }

    public static Integer getRemainSecondsOneDay(Date currentDate) {
        //获取当前时间,到今晚12点的剩余秒
        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 seconds = ChronoUnit.SECONDS.between(currentDateTime, midnight);
        return (int) seconds;
    }

猜你喜欢

转载自blog.csdn.net/qazwsx081/article/details/84637692
今日推荐