I need to format a ZonedDate time to format MM/dd/yyyy
.
ZonedDateTime zonedDateTime = ZonedDateTime.now();
String date = DateTimeFormatter.ofPattern("MM/dd/yyyy").format(zonedDateTime);
ZonedDateTime zoneDate = ZonedDateTime.parse(date);
Getting error:
Exception in thread "main" java.time.format.DateTimeParseException: Text '12/05/2018' could not be parsed at index 0
Or if I convert my value to a String with the format I want and then try to parse it back a ZonedDate Time with my format once again:
DateTimeFormatter format = DateTimeFormatter.ofPattern("MM/dd/yyyy");
ZonedDateTime zonedDateTime = ZonedDateTime.now();
String date = DateTimeFormatter.ofPattern("MM/dd/yyyy").format(zonedDateTime);
ZonedDateTime zonedate = ZonedDateTime.parse(date, format);
I get error:
Exception in thread "main" java.time.format.DateTimeParseException: Text '12/05/2018' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2018-12-05 of type java.time.format.Parsed
I've seen plenty of questions on this, but I keep getting these parsing errors