本文介绍了ZonedDateTime到UTC并应用了偏移量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Java 8 这就是我的 ZonedDateTime 看起来像
2013-07-10T02:52:49+12:00我得到这个值为
z1.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)其中 z1 是 ZonedDateTime 。
我想将此值转换为 2013-07-10T14:52:49
我该怎么做?
推荐答案<这是你想要的吗? 这会将 ZonedDateTime 转换为 LocalDateTime ,并且给定 ZoneId 之前将 ZonedDateTime 转换为 Instant 。
Is this what you want? This converts your ZonedDateTime to a LocalDateTime with a given ZoneId by converting your ZonedDateTime to an Instant before.
LocalDateTime localDateTime = LocalDateTime.ofInstant(z1.toInstant(), ZoneId.of("UTC"));或许你想要用户系统时区而不是硬编码的UTC:
Or maybe you want the users system-timezone instead of hardcoded UTC:
LocalDateTime localDateTime = LocalDateTime.ofInstant(z1.toInstant(), ZoneId.systemDefault());更多推荐
ZonedDateTime到UTC并应用了偏移量?
发布评论