fork download
  1. import java.time.*;
  2. import java.time.format.DateTimeFormatter;
  3. import java.util.Locale;
  4. import java.util.stream.Stream;
  5.  
  6. public class Main {
  7. static final DateTimeFormatter fmt = DateTimeFormatter.ofPattern(
  8. "uuuu-MM-dd HH:mm:ss[.[SSS][SS][S]] XX VV",
  9. Locale.ENGLISH);
  10.  
  11. public static void main(String[] args) {
  12. Stream.of(
  13. "2019-06-20 12:18:07.207 +0000 UTC",
  14. "2019-06-20 12:18:07.20 +0000 UTC",
  15. "2019-06-20 12:18:07.2 +0000 UTC",
  16. "2019-06-20 12:18:07 +0000 UTC"
  17. )
  18. .map(s -> OffsetDateTime.parse(s, fmt))
  19. .forEach(System.out::println);
  20. }
  21. }
Success #stdin #stdout 0.13s 55176KB
stdin
Standard input is empty
stdout
2019-06-20T12:18:07.207Z
2019-06-20T12:18:07.200Z
2019-06-20T12:18:07.200Z
2019-06-20T12:18:07Z