How can I convert a time in milliseconds to ZonedDateTime

Ted pottel :

I have the time in milliseconds and I need to convert it to a ZonedDateTime object.

I have the following code

long m = System.currentTimeMillis();
LocalDateTime d = LocalDateTime.millsToLocalDateTime(m);

The line

LocalDateTime d = LocalDateTime.millsToLocalDateTime(m);

gives me a error saying methed millsToLocalDateTime is undefined for type LocalDateTime

xingbin :

ZonedDateTime and LocalDateTime are different.

If you need LocalDateTime, you can do it this way:

long m = ...;
Instant instant = Instant.ofEpochMilli(m);
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=99173&siteId=1