fork download
  1. import java.time.DateTimeException;
  2. import java.time.Instant;
  3. import java.time.format.DateTimeFormatter;
  4. import java.util.Locale;
  5. import java.util.stream.Stream;
  6.  
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10. Stream.of(
  11. "So., 18 Juli 2021 15:24:00 +0200",
  12. "ven., 16 avr. 2021 15:24:00 +0200",
  13. "vr, 16 apr. 2021 15:24:00 +0200",
  14. "vr, 16 07 2021 15:24:00 +0200"
  15. ).forEach(s -> {
  16. Stream.of(
  17. Locale.GERMANY,
  18. Locale.FRANCE,
  19. new Locale("nl", "NL")
  20. ).forEach( locale -> {
  21. try {
  22. System.out.println("Parsed '" + s + "' using the locale, " + locale + " => " + parseToInstant(s, locale));
  23. }catch(DateTimeException e) {
  24. //....
  25. }
  26. });
  27. });
  28. }
  29.  
  30. static Instant parseToInstant(String strDateTime, Locale locale) {
  31. return DateTimeFormatter.ofPattern("E, d [MMMM][MMM][M] u H:m:s Z").withLocale(locale).parse(strDateTime,
  32. Instant::from);
  33. }
  34. }
Success #stdin #stdout 0.29s 57584KB
stdin
Standard input is empty
stdout
Parsed 'So., 18 Juli 2021 15:24:00 +0200' using the locale, de_DE => 2021-07-18T13:24:00Z
Parsed 'ven., 16 avr. 2021 15:24:00 +0200' using the locale, fr_FR => 2021-04-16T13:24:00Z
Parsed 'vr, 16 apr. 2021 15:24:00 +0200' using the locale, nl_NL => 2021-04-16T13:24:00Z
Parsed 'vr, 16 07 2021 15:24:00 +0200' using the locale, nl_NL => 2021-07-16T13:24:00Z