gpt4 book ai didi

java - 应用偏移量的 ZonedDateTime 到 UTC?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:52:26 26 4
gpt4 key购买 nike

我正在使用 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 转换为具有给定 ZoneIdLocalDateTime,方法是将您的 ZonedDateTime 转换为 Instant 之前。

LocalDateTime localDateTime = LocalDateTime.ofInstant(z1.toInstant(), ZoneOffset.UTC);

或者您可能想要用户系统时区而不是硬编码的 UTC:

LocalDateTime localDateTime = LocalDateTime.ofInstant(z1.toInstant(), ZoneId.systemDefault());

关于java - 应用偏移量的 ZonedDateTime 到 UTC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35689123/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com