Java 8 DateTimeFormatter 无法解析自己格式化的日期

Java 8 DateTimeFormatter can't parse a date formatted by itself

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss z");
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault());
// 2016-10-10 09:28:45 PDT
String s = zonedDateTime.format(formatter);
// this call fails
ZonedDateTime.parse(s, formatter);

给定的片段有什么问题,formatter.parse(date.format(formatter)) 不应该评估为相同的 date 吗?
例外:

java.time.DateTimeException: Unable to obtain LocalTime from TemporalAccessor: {MilliOfSecond=0, MicroOfSecond=0, HourOfAmPm=9, MinuteOfHour=28, NanoOfSecond=0, SecondOfMinute=45},ISO,America/Los_Angeles resolved to 2016-10-10 of type java.time.format.Parsed

由于您为 12 小时制指定了 hh(小写 h),因此您丢失了有关这是否是 AM/PM 的信息,因此解析会抱怨这一点。

使用 yyyy-MM-dd hh:mm:ss a Z 包含 AM/PM 指标有效。

java.time.ZonedDateTime.parse("2016-10-10T09:28:45-07:00");

java.time.LocalDate.parse("2016-10-10");