fork download
  1. import java.time.Instant;
  2. import java.time.LocalDateTime;
  3. import java.time.ZoneId;
  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. Instant instantParsed = LocalDateTime.parse(strDateTime, parser)
  17. .atZone(ZoneId.of("Europe/Vienna"))
  18. .toInstant();
  19. System.out.println("Instant received from the server: " + instantParsed);
  20.  
  21. Instant instantNow = Instant.now();
  22. System.out.println("Current instant: " + instantNow);
  23.  
  24. System.out.println(ChronoUnit.MINUTES.between(instantParsed, instantNow) > 1);
  25. }
  26. }
  27.  
Success #stdin #stdout 0.22s 57140KB
stdin
Standard input is empty
stdout
Instant received from the server: 2023-01-07T15:39:15Z
Current instant: 2023-01-07T18:01:46.533554Z
true