【发布时间】:2016-08-20 19:35:16
【问题描述】:
如何将 ZoneId 转换为 DateTimeZone? 我有:
Private Instant logTime; //java.time
Private ZoneId timeZoneId; //java.time
但我需要从上面获取 DateTime 和 DateTimeZone(均为 org.joda.time)。我从 Instant 得到 DateTime 喜欢 =
Private DateTime dateTime ; //org.joda.time
private DateTimeZone dateTimeZone; //org.joda.time
LocalDateTime currentTime = new LocalDateTime(logTime);
dateTime = currentTime.toDateTime();
对于 dateTimeZone,我做到了:
dateTimeZone = DateTimeZone.forID(timeZoneId.getId()); // getting java.lang.NullPointerException
但出现错误。有人可以告诉mw如何正确地做到这一点
这给了我错误。有人可以告诉我应该如何转换它。我需要获取给定 zoneId 的当前时间。
【问题讨论】:
-
A
ZoneId没有任何日期/时间信息。您的意思是获取特定区域 ID 中的当前时间吗? -
所以我可以获取特定区域 id 中的当前时间(localTimezone)?
-
你能edit你的帖子说明你有什么和你想要什么吗?因为目前还不清楚。
-
jodatime 中没有
ZoneId类。这是来自java.time的课程。混合使用这两个 API 会引起很多混乱,因为许多类的名称相同。例如,不清楚private Instant logTime是java.time.Instant还是org.joda.time.Instant -
用您遇到的错误更新您的问题。请阅读How to Ask 和minimal reproducible example 了解指南。