public static void main(String[] args) { LocalDateTime fromDateTime = LocalDateTime.of(2018, 9, 11, 7, 45, 55); LocalDateTime toDateTime = LocalDateTime.of(2019, 9, 10, 7, 40, 45); LocalDateTime tempDateTime = LocalDateTime.from( fromDateTime ); long days = tempDateTime.until( toDateTime, ChronoUnit.DAYS); tempDateTime = tempDateTime.plusDays( days ); long hours = tempDateTime.until( toDateTime, ChronoUnit.HOURS); tempDateTime = tempDateTime.plusHours( hours ); long minutes = tempDateTime.until( toDateTime, ChronoUnit.MINUTES); tempDateTime = tempDateTime.plusMinutes( minutes ); long seconds = tempDateTime.until( toDateTime, ChronoUnit.SECONDS); System.out.println( days + " 天 " + hours + " 小时 " + minutes + " 分 " + seconds + " 秒."); }
相关文章: