Close

Java - How to convert epoch milliseconds to LocalDateTime?

[Last Updated: 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;
    }
}
2020-08-04T02:27:38.889

See Also