Java8使用Instant 判断两个日期相距多少时间

 public static void main(String[] args) throws InterruptedException {
        Date currentTime = new Date();
        Thread.sleep(1000);
        Instant instant = currentTime.toInstant();
        //毫秒
        long haomiao = ChronoUnit.MILLIS.between(instant, Instant.now());
        long fen = ChronoUnit.MINUTES.between(instant, Instant.now());
        long miao = ChronoUnit.SECONDS.between(instant, Instant.now());
        System.out.println(haomiao);
    }
发布了133 篇原创文章 · 获赞 32 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/corleone_4ever/article/details/104402995