-3

There are 2 data as below. I will subtract these data from each other and check if there is a 10-minute difference between them. How can I do this in 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
Thomas
  • 87,414
  • 12
  • 119
  • 157
  • A possibly simpler way is to add 10 minutes to the earlier date-time and see if the result is after the other one. – Ole V.V. Nov 03 '22 at 18:08

1 Answers1

0
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());