fork download
  1. import java.time.Instant;
  2. import java.time.ZoneId;
  3. import java.time.ZonedDateTime;
  4. import java.time.format.DateTimeFormatter;
  5. import java.util.Locale;
  6.  
  7. class Main {
  8. public static void main(String[] args) {
  9. // Convert epoch seconds to Instant
  10. Instant instant = Instant.ofEpochSecond(1386696238L);
  11. System.out.println(instant);
  12.  
  13. // ZoneId.systemDefault() returns the ZoneId set to the JVM. Replace it
  14. // as desired e.g. to ZoneId.of("America/New_York")
  15. ZonedDateTime zdt = instant.atZone(ZoneId.systemDefault());
  16. System.out.println(zdt);
  17.  
  18. // String representation in a custom format
  19. String formatted = zdt.format(DateTimeFormatter.ofPattern(
  20. "MM/dd/uuuu", Locale.ENGLISH));
  21. System.out.println(formatted);
  22. }
  23. }
Success #stdin #stdout 0.16s 56672KB
stdin
Standard input is empty
stdout
2013-12-10T17:23:58Z
2013-12-10T17:23:58Z[GMT]
12/10/2013