如何将以毫秒为单位的时间转换为ZonedDateTime [英] How can I convert a time in milliseconds to ZonedDateTime

查看:68
本文介绍了如何将以毫秒为单位的时间转换为ZonedDateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的时间以毫秒为单位,我需要将其转换为ZonedDateTime对象.

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

我有以下代码

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

LocalDateTime d = LocalDateTime.millsToLocalDateTime(m);

给我一​​个错误的说法对于LocalDateTime类型,metheds millsToLocalDateTime是未定义的

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

推荐答案

ZonedDateTime LocalDateTime 如果您需要 LocalDateTime ,则可以通过以下方式进行操作:

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

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

这篇关于如何将以毫秒为单位的时间转换为ZonedDateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆