fork download
  1. import java.time.*;
  2. import java.time.format.DateTimeFormatter;
  3. import java.time.format.DateTimeFormatterBuilder;
  4. import java.util.Locale;
  5.  
  6. public class Main {
  7. static final DateTimeFormatter fmt = new DateTimeFormatterBuilder()
  8. .append(DateTimeFormatter.ISO_LOCAL_DATE)
  9. .appendLiteral(' ')
  10. .append(DateTimeFormatter.ISO_LOCAL_TIME)
  11. .appendPattern(" XX VV")
  12. .toFormatter(Locale.ENGLISH);
  13.  
  14. public static void main(String[] args) {
  15. OffsetDateTime odt = OffsetDateTime.parse("2019-06-20 12:18:07.207 +0000 UTC", fmt);
  16. System.out.println(odt);
  17.  
  18. // Let's say the target time zone is America/New_York
  19. ZoneId zoneId = ZoneId.of("America/New_York");
  20. ZonedDateTime zdtNY = odt.atZoneSameInstant(zoneId);
  21. System.out.println(zdtNY);
  22. LocalDateTime ldtNY = zdtNY.toLocalDateTime();
  23. System.out.println(ldtNY);
  24. }
  25. }
Success #stdin #stdout 0.17s 59744KB
stdin
Standard input is empty
stdout
2019-06-20T12:18:07.207Z
2019-06-20T08:18:07.207-04:00[America/New_York]
2019-06-20T08:18:07.207