How can I convert a time in milliseconds to ZonedDateTime

前端 未结 4 611
忘了有多久
忘了有多久 2021-01-13 03:18

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();
L         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-13 04:02

    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());
    

提交回复
热议问题