My data is of format '2023-12-20T23:15:49.680Z'. This looks like ISO 8601.
I need to convert this to a java.sql TimeStamp.
I tried using this and a few other formats, none of which work: @CsvDate(value = "yyyy-MM-dd'T'HH:mm:ss")
org.apache.commons.beanutils.ConversionException: String must be in JDBC format [yyyy-MM-dd HH:mm:ss.fffffffff] to create a java.sql.Timestamp
What is the correct format to use?
No, you don’t.
That terribly flawed class
Timestampwas years ago supplanted by the modern java.time classes defined in JSR 310.Parse your ISO 8601 compliant string as a
java.time.Instantobject.The
Zon the end of your input string means an offset from UTC of zero hours-minutes-seconds. Pronounced “Zulu”. TheInstantclass has the same meaning, representing a moment with an offset of zero.To create a
Stringwith text in that ISO 8601 format, calltoString.If you need to interoperate with old code not yet updated to java.time, call the new conversion methods added to the old classes.
When you receive a
java.sql.Timestampobject, immediately convert to anInstant.But avoid the legacy dae-time classes wherever possible. They really are the bad.
You said:
No, it does not. Use
Instantrather thanTimestampand all your problems go away.Always use ISO 8601 formats when exchanging date-time data as text.