JodaTime 对时区偏移感到困惑
JodaTime confused about TimeZone offset
我收到一个类似 "2018-06-21T13:30:00Z"
的日期字符串
我用 "yyyy-MM-dd'T'HH:mm:ssZ"
模式解析它
我现在是 GMT+2,结果看起来像 2018-06-21T15:30:00.000+02:00
虽然我希望它看起来像这样 2018-06-21T13:30:00.000+02:00
是否应该已经在结果的 HH:mm:ss
部分应用了偏移量?
代码
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").parseDateTime("2018-06-21T13:30:00Z")
joda:2.9.7
是的,给定的日期时间是当地时间+02:00。
从 ISO 8601 Wikipedia 与 UTC 的时间偏移:
The following times all refer to the same moment: "18:30Z", "22:30+04", "1130−0700", and "15:00−03:30". Nautical time zone letters are not used with the exception of Z. To calculate UTC time one has to subtract the offset from the local time, e.g. for "15:00−03:30" do 15:00 − (−03:30) to get 18:30 UTC.
因此对于您的情况:2018-06-21T15:30:00.000+02:00
表示 15:30 - 02:00 因此 UTC 为 13:30
我收到一个类似 "2018-06-21T13:30:00Z"
的日期字符串
我用 "yyyy-MM-dd'T'HH:mm:ssZ"
我现在是 GMT+2,结果看起来像 2018-06-21T15:30:00.000+02:00
虽然我希望它看起来像这样 2018-06-21T13:30:00.000+02:00
是否应该已经在结果的 HH:mm:ss
部分应用了偏移量?
代码
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").parseDateTime("2018-06-21T13:30:00Z")
joda:2.9.7
是的,给定的日期时间是当地时间+02:00。
从 ISO 8601 Wikipedia 与 UTC 的时间偏移:
The following times all refer to the same moment: "18:30Z", "22:30+04", "1130−0700", and "15:00−03:30". Nautical time zone letters are not used with the exception of Z. To calculate UTC time one has to subtract the offset from the local time, e.g. for "15:00−03:30" do 15:00 − (−03:30) to get 18:30 UTC.
因此对于您的情况:2018-06-21T15:30:00.000+02:00
表示 15:30 - 02:00 因此 UTC 为 13:30