I am trying to parse the current timestamp with specific format but every try I keep getting a java.time.format.DateTimeParseException
. My code:
ZonedDateTime.parse(
ZonedDateTime.now().toString(),
DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss.SSS")
.withZone(ZoneId.of("UTC")) //I also tried ZoneId.systemDefault()
)
Result:
java.time.format.DateTimeParseException:
Text '2018-02-27T11:01:18.776+01:00[Europe/Berlin]' could not be parsed at index 2
The question is why I can't parse it in the desired format and how to achieve it?
P.S. I also saw this post and tried setting the ZoneId
but it didn't help.