0

I'm trying to parse a date_time string from an api I'm getting but it doesn't seem to work.

I've tried every variation of LocalDateTime.parse() with the various predefined ISO formats in DateTimeFormatter. I've also tried using OffSetDateTime and it still doesn't work.

I keep getting this error

java.time.format.DateTimeParseException: Text '2016-05-15T05:30:00.000+0000' could not be parsed at index 23

Which seems weird since an offset formatter should recognize the '+' character, no? Anyone know how I should be parsing it?

WinterDev
  • 349
  • 1
  • 9
  • What did you try as format? And what did you try to parse it into, a `LocalDateTime`, a `ZonedDateTime`? – Tunaki May 09 '16 at 14:17
  • I tried to format the exact string in the error: 2016-05-15T05:30:00.000+0000 using OffSetDateTime edit: ZonedDateTime and LocalDateTime don't work either. – WinterDev May 09 '16 at 14:22
  • But what was the pattern you tried? Could you post all of the pattern you tried and what when wrong? – Tunaki May 09 '16 at 14:25
  • Like I said in the post, I tried ISO patterns. for example DateTimeFormatter.ISO_OFFSET_DATE_TIME, ISO_LOCAL_DATE_TIME, ISO_ZONED_DATE_TIME, ... Literally tried every one of them with both OffsetDateTime, ZonedDateTime and LocalDateTime. – WinterDev May 09 '16 at 14:30
  • You need to make your own. See the linked question. – Tunaki May 09 '16 at 14:32
  • Have you noticed all those formats have colons in the offset? `2016-05-15T05:30:00.000+00:00` works fine for `ISO_OFFSET_DATE_TIME`. If you must accept `+0000` instead of `+00:00`, then you have to roll your own. – dcsohl May 09 '16 at 14:47
  • ya, that was the problem. I made my own format and now it works. Thanks! – WinterDev May 09 '16 at 15:17
  • I re-opened and re-closed this Question to target the much closer original Questions: [*Java 8 Date and Time: parse ISO 8601 string without colon in offset*](https://stackoverflow.com/q/46487403/642706) and [*Cannot parse String in ISO 8601 format, lacking colon in offset, to Java 8 Date*](https://stackoverflow.com/q/43360852/642706). Whoops, now I see *this* Question here was earlier -- the other two have good Answers, so I guess I'll leave it be now. – Basil Bourque Oct 01 '18 at 01:54

0 Answers0