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);
What's wrong with the given snippet, shouldn't formatter.parse(date.format(formatter)) evaluate to the same date ?
Exception :
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