fork download
  1. import java.time.LocalDate;
  2. import java.time.LocalTime;
  3. import java.time.ZoneId;
  4. import java.time.ZonedDateTime;
  5. import java.time.format.DateTimeFormatter;
  6. import java.util.Locale;
  7.  
  8. public class Main {
  9. public static void main(String[] args) {
  10. ZonedDateTime zdtUtc = ZonedDateTime.of(LocalDate.of(2013, 11, 15), LocalTime.of(0, 28, 44),
  11. ZoneId.of("Etc/UTC"));
  12.  
  13. ZonedDateTime zdtNewYork = zdtUtc.withZoneSameInstant(ZoneId.of("America/New_York"));
  14.  
  15. System.out.println(zdtNewYork);
  16.  
  17. // Custom format
  18. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss z uuuu", Locale.ENGLISH);
  19. System.out.println(zdtNewYork.format(dtf));
  20. }
  21. }
Success #stdin #stdout 0.21s 56188KB
stdin
Standard input is empty
stdout
2013-11-14T19:28:44-05:00[America/New_York]
Thu Nov 14 19:28:44 EST 2013