LocalDateTime计算时间差

LocalDateTime时间差计算(计算天数)

public static void main(String[] args) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String pubTime="2019-11-05 16:49:15";
        String pubEndTime="2019-11-20 16:48:15";

        LocalDateTime startTime = LocalDateTime.parse(pubTime, df);
        LocalDateTime endTime = LocalDateTime.parse(pubEndTime, df);
        Duration duration = Duration.between(startTime,endTime);
        long count = duration.toMillis();
        System.out.println(count);
        System.out.println("相差天数:" + count / (3600 * 24 *1000));

    }
上一篇:JAVA 取当前系统时间后三天零时(LocalDateTime)


下一篇:JAVA8新特性