Close

Java - How to convert epoch milliseconds to LocalDateTime?

[Updated: Apr 28, 2017, Created: Apr 28, 2017]

Java Date Time Java 

In this quick example, we will show how to convert epoch milliseconds to LocalDateTime

public class MillisToLocalDateTimeExample {
  public static void main(String[] args) {
      long m = System.currentTimeMillis();
      LocalDateTime d = millsToLocalDateTime(m);
      System.out.println(d);
  }

  public static LocalDateTime millsToLocalDateTime(long millis) {
      Instant instant = Instant.ofEpochMilli(millis);
      LocalDateTime date = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
      return date;
  }
}

Output

2017-05-01T15:44:39.134

See Also