如何在Java中获得两个日期时间数据之间的差异



有两个数据如下。我将把这些数据相互减去,并检查它们之间是否有10分钟的差异。我如何在java中做到这一点?

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");  
LocalDateTime now = LocalDateTime.now(); 
String db_share_time="2022-05-12 12:15:39";
System.out.println(dtf.format(dtf.parse(db_share_time)));
System.out.println(dtf.format(now));
Output:
2022-05-12 12:15:39
2022-11-03 14:42:28
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime now = LocalDateTime.now();
String db_share_time = "2022-05-12 12:15:39";
LocalDateTime from = LocalDateTime.from(dtf.parse(db_share_time));
Duration between = Duration.between(from, now);
System.out.println(between.toMinutes());

相关内容

  • 没有找到相关文章