javatimezonejava-timedatetime-parsingdatetimeformatter

MESZ is not recognized in the pattern of DateTimeFormatter of Java


LocalDateTime time = LocalDateTime.parse("27. April 2021 00:03:50 MESZ", DateTimeFormatter.ofPattern("dd. MMMM yyyy HH:mm:ss z"));

Trying to parse time string as shown above. 'z' in the pattern is not able to recognize "MESZ" time zone.

Can someone tell me if there is any other pattern I have to use to match "MESZ"?


Solution

  • I found the answer. I have to use DateTimeFormatter with Locale

    DateTimeFormatter FORMATTER = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).withLocale(Locale.GERMANY);
    LocalDateTime time = LocalDateTime.parse("27. April 2021 00:03:50 MESZ", FORMATTER);