如果未指定时区,Joda DateTimeFormatter 中的默认时区是什么?

What is the default time zone in Joda DateTimeFormatter if time zone is not specified?

我对Joda DateTimeFormatter不熟悉,所以我想知道如果没有为DateTimeFormatter指定时区,那么默认时区是什么?例如我有:

DateTimeFormatter stdFormatter = DateTimeFormat.forPattern("MM/dd/yyyy");
DateTime today = stdFormatter.parseDateTime("07/20/2017");

在这种情况下,today 的时区是什么?默认是 2017-07-20 00:00:00 UTC 吗?谢谢!

参考 DateTime 文档 here,DateTime 在内部将值存储为 1970-01-01T 之后的毫秒数00:00:00Z,其中 Z 是 UTC 时区。

它的输出方式取决于您决定如何格式化它(即,如果您想在不同的时区打印 DateTime,您可以使用 Joda 库来实现)。

在这种情况下,DateTimeFormat.forPattern 使用 JVM 默认语言环境,它由 Locale.getDefault() 决定,无论您选择哪种语言环境。因此,您的 DateTime 将包含 '07/20/2017 00:00:00 {YOUR TIME ZONE}'.

的 UTC 时间

假设您的时区是 PDT(即 UTC-7)。然后“07/20/2017 00:00:00 PDT”==“07/20/2017 07:00:00 UTC”。您的 DateTime 对象将存储该 UTC 时间。