fork(1) download
  1. import java.time.Instant;
  2. import java.time.OffsetDateTime;
  3. import java.time.ZoneOffset;
  4. import java.time.format.DateTimeFormatter;
  5. import java.util.Locale;
  6.  
  7. public class Main {
  8. public static void main(String[] args) {
  9. // An example epoch milliseconds
  10. long millis = 1631113620000L;
  11. Instant instant = Instant.ofEpochMilli(millis);
  12. String strDateTime = instant.toString();
  13. System.out.println(strDateTime);
  14.  
  15. // If you need the value strictly in the pattern, yyyy-MM-dd'T'HH:mm:ss.SSSXXX
  16. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ss.SSSXXX", Locale.ENGLISH);
  17. OffsetDateTime odt = instant.atOffset(ZoneOffset.UTC);
  18. strDateTime = odt.format(dtf);
  19. System.out.println(strDateTime);
  20. }
  21. }
Success #stdin #stdout 0.1s 48896KB
stdin
Standard input is empty
stdout
2021-09-08T15:07:00Z
2021-09-08T15:07:00.000Z