fork(1) download
  1. import java.time.Instant;
  2. import java.time.ZoneId;
  3. import java.time.ZoneOffset;
  4. import java.time.format.DateTimeFormatter;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. // With a set offset
  12. System.out.println(
  13. Instant.parse("2019-07-14T18:30:00.000Z")
  14. .atOffset(
  15. ZoneOffset.ofHours(-2)
  16. )
  17. .format(
  18. DateTimeFormatter.ofPattern("uuuu-MM-dd hh:mm:ss a")
  19. )
  20. );
  21.  
  22. // Or, with a specific zone (recommended):
  23. System.out.println(
  24. Instant.parse("2019-07-14T18:30:00.000Z")
  25. .atZone(
  26. ZoneId.of("America/Noronha") // Specify your zone here, or use ZoneId.systemDefault()
  27. )
  28. .format(
  29. DateTimeFormatter.ofPattern("uuuu-MM-dd hh:mm:ss a")
  30. )
  31. );
  32.  
  33. }
  34. }
Success #stdin #stdout 0.12s 37528KB
stdin
Standard input is empty
stdout
2019-07-14 04:30:00 PM
2019-07-14 04:30:00 PM