📜  java中的测试日期 - 任何代码示例

📅  最后修改于: 2022-03-11 14:56:15.259000             🧑  作者: Mango

代码示例1
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MM-yyyy");
String inputString1 = "23-01-1997";
String inputString2 = "27-04-1997";

try {
    LocalDateTime date1 = LocalDate.parse(inputString1, dtf);
    LocalDateTime date2 = LocalDate.parse(inputString2, dtf);
    long daysBetween = Duration.between(date1, date2).toDays();
    System.out.println ("Days: " + daysBetween);
} catch (ParseException e) {
    e.printStackTrace();
}