Android Joda Time - 如何从文件加载 UTC

Android Joda Time - How to Load UTC from File

我正在使用 Joda Time。我想比较2 dates/times A和B来判断B是否超过了A.

问题 - 当我 logcat A 时它不是 UTC。当我 logcat B 它在 UTC 中。所以这个比较是不真实的。

A - A UTC time loaded from a file
B -The "System Time" in UTC

代码:

A - DateTime csvTime = new DateTime( inArray[5] ) ; //inArray[x] is loaded from a file and has this format: 2017-02-10T01:09:00Z
B - new DateTime(DateTimeZone.UTC)

问题 - 如何加载 inArray[5] 使其真正采用 UTC 并与 B 准确比较?

提前致谢,是的,我已经查看了 100 多个 post。我还没有找到一个 post 告诉我上面 A 的语法,如何在 UTC 内部存储外部 ISO 8601 格式日期。我玩过 TimeZone set default to force Joda/JVMP default TZ 但这让我不得不指定我不想做的 TimeZone。

如果您的输入已经是 UTC(尾随 "Z"),那么我建议您这样解析:

DateTime dt =
    ISODateTimeFormat.dateTimeNoMillis().withOffsetParsed().parseDateTime(
        "2017-02-10T01:09:00Z"
    );
System.out.println(dt); // 2017-02-10T01:09:00.000Z

否则,您可以通过 withZone(DateTimeZone.UTC) 将 A-DateTime 转换为 UTC。