如何将以毫秒为单位的时间转换为ZonedDateTime

如何将以毫秒为单位的时间转换为ZonedDateTime

本文介绍了如何将以毫秒为单位的时间转换为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 sayingmethed 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:47