Java 计算两个日期的时间间隔

@Test
public void durationTest(){
    Temporal begin = LocalDateTime.of(2000,1,1,0,0);
    Temporal end = LocalDateTime.of(2020,12,23,0,0);
    Duration duration = Duration.between(begin, end);
    System.out.println("duration.toDays() = " + duration.toDays());
    System.out.println("duration.toHours() = " + duration.toHours());
    System.out.println("duration.toMinutes() = " + duration.toMinutes());
    System.out.println("duration.toMillis() = " + duration.toMillis());
    System.out.println("duration.toNanos() = " + duration.toNanos());
}

输出为
duration.toDays() = 7662
duration.toHours() = 183888
duration.toMinutes() = 11033280
duration.toMillis() = 661996800000
duration.toNanos() = 661996800000000000

posted @ 2021-01-03 21:37  无法手执玫瑰  阅读(3780)  评论(0编辑  收藏  举报