计算时间 年 月 日 时 分差 LocalDateTime now = LocalDateTime.now(); LocalDateTime of = LocalDateTime.of(2021, 9, 1, 12, 00, 00, 0); LocalDateTime asd = LocalDateTime.now(); String s = formatDurationBetween(now, of); System.out.println(s); public static String formatDurationBetween(LocalDateTime from, LocalDateTime to) { Duration difference = Duration.between(from, to); long days = difference.toDays(); difference = difference.minusDays(days); long hours = difference.toHours(); long mins = difference.minusHours(hours).toMinutes(); // 根据需求返回响应数据 return String.format("%dd %dh %02dm", days, hours, mins); }