Java 8's LocalDateTime
has an ofEpochSecond
method. Unfortunately, there is no such method in the ZonedDateTime
. Now, I have an Epoch value and an explicit ZoneId
given. How do I get a ZonedDateTime
out of these?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You should be able to do this via the Instant
class, which can represent a moment given the epoch time. If you have epoch seconds, you might create something via something like
Instant i = Instant.ofEpochSecond(t);
ZonedDateTime z = ZonedDateTime.ofInstant(i, zoneId);