0

I'm stuck on a conversion problem from a String to a ZonedDateTime in Java.

I have the following String :

String str = "2019-06-13T09:27:07.233+0000";

that I would like to convert to a ZonedDateTime. So far I've been trying with and without formatters but I keep getting an error. Here's my code :

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
return ZonedDateTime.parse(str, formatter);

The error I get is :

Text '2019-06-13T09:27:07.233+0000' could not be parsed at index 23.

I've tried several custom patterns as well as ISO_DATE_TIME and ISO_OFFSET_DATE_TIME but none of them worked...

Anyone would have any idea of the correct pattern for this one ?

Thank you !

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Malemort
  • 19
  • 2
  • 2
    Your pattern specifies a literal letter Z. Your string does not end with literally the letter Z. Remove the two `'` around Z. – Michael Dec 05 '19 at 16:31
  • @Michael Indeed, it appears to be working with pattern "yyyy-MM-dd'T'HH:mm:ss.SSSZ", thank you! – Malemort Dec 05 '19 at 16:36
  • Does this answer your question? [Parse and retrieve timezone offset from date-time](https://stackoverflow.com/questions/48230408/parse-and-retrieve-timezone-offset-from-date-time) – Ole V.V. Dec 07 '19 at 16:56

0 Answers0