2

I'm trying to parse a csv entry "2021-05-09T12:23:55+0100" as an OffsetDateTime using openCsv as follows:

@CsvDate(value = "yyyy-MM-dd'T'HH:mm:ssZ")
override var orderTimeStamp: OffsetDateTime? = null

Based on various suggestions from other posts, I've tried out the following formats:

  • "yyyy-MM-dd'T'HH:mm:ssZ"
  • "yyyy-MM-dd'T'HH:mm:ss'Z'"
  • "yyyy-MM-dd'T'HH:mm:ss+ZZZZ"
  • "yyyy-MM-dd'T'HH:mm:ss'+'Z"
  • "yyyy-MM-dd'T'HH:mm:ssX"
  • etc...

Each time, I get the same error:

 com.opencsv.exceptions.CsvDataTypeMismatchException: Conversion of 2021-05-09T12:23:55+0100 to java.time.OffsetDateTime failed.

Does anyone know which specific format would correctly parse this? Thanks!

sigma1510
  • 1,165
  • 1
  • 11
  • 26
  • What about the pattern `"uuuu-MM-dd'T'HH:mm:ssxx"`? It works for me (in Java, and using `u` instead of `y` is not necessary, but also right)... It's the two `x` in the end. – deHaar Jun 09 '21 at 13:11
  • No, that didn't work, unfortunately. But thank you. Should they be capitalized maybe? – sigma1510 Jun 09 '21 at 13:19
  • 2
    Using a `DateTimeFormatter.ofPattern("uuuu-MM-dd'T'HH:mm:ssxx");` directly is definitely working. But I don't know what's behind the scenes when using a `@CsvDate` annotation. Try upper case `X` or even `X`s and some other patterns. A single lower case `x` is also working (in Java). – deHaar Jun 09 '21 at 13:55
  • Not going to post this as the main answer, because it's not very satisfying, but if anyone runs into a similar problem and needs a quick fix, I ended up importing it as a string and mapping it using a DateTimeFormatter as above before use. – sigma1510 Jun 16 '21 at 15:15

0 Answers0