Home > database >  How to parse "2021-11-20 01:00" formatted date to LocalDateTime - error
How to parse "2021-11-20 01:00" formatted date to LocalDateTime - error

Time:11-21

How to parse "2021-11-20 01:00" formatted date to LocalDateTime? I'm trying like:

LocalDateTime date = LocalDateTime.parse("2021-11-20 01:00", DateTimeFormatter.ofPattern("yyyy-MM-ddxxx"));

But getting this strange error:

java.time.format.DateTimeParseException: Text '2021-11-20 01:00' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {OffsetSeconds=3600},ISO resolved to 2021-11-20 of type java.time.format.Parsed

Any suggestions? This time format is used by European VIES VAT ID checking system when receiving XML (SOAP) response: <requestDate>2021-11-20 01:00</requestDate>. The same error with OffsetDateTime. And the same with ZonedDateTime...

CodePudding user response:

You can specify ur pattern by yourself as String like this:

String str = "2021-11-20 01:00";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
LocalDateTime date= LocalDateTime.parse(str, formatter);
  • Related