fork download
  1. import java.time.LocalDateTime;
  2. import java.time.ZoneId;
  3. import java.time.ZonedDateTime;
  4. import java.time.format.DateTimeFormatter;
  5. import java.time.temporal.ChronoUnit;
  6. import java.util.Locale;
  7.  
  8. class Main {
  9. public static void main(String[] args) {
  10. String strDateTime = "Sa. 07.01.2023 16:39:15";
  11.  
  12. DateTimeFormatter parser = DateTimeFormatter.ofPattern("EEE dd.MM.uuuu HH:mm:ss", Locale.GERMAN);
  13.  
  14. // Note: change the ZoneId as per your requirement
  15.  
  16. ZonedDateTime zdt = LocalDateTime.parse(strDateTime, parser)
  17. .atZone(ZoneId.of("Europe/Vienna"));
  18. System.out.println("Date-time received from the server: " + zdt);
  19.  
  20. ZonedDateTime now = ZonedDateTime.now(zdt.getZone());
  21. System.out.println("Current date-time: " + now);
  22.  
  23. System.out.println(ChronoUnit.MINUTES.between(zdt, now) > 1);
  24. }
  25. }
  26.  
Success #stdin #stdout 0.21s 55308KB
stdin
Standard input is empty
stdout
Date-time received from the server: 2023-01-07T16:39:15+01:00[Europe/Vienna]
Current date-time: 2023-01-07T17:46:43.576073+01:00[Europe/Vienna]
true