This is a Java 8 solution. It relies on the java.time
library.
String isoStamp = "2013-10-27T13:00:00.325234Z";
OffsetDateTime odt = OffsetDateTime.parse(
isoStamp,
DateTimeFormatter.ISO_OFFSET_DATE_TIME );
The OffsetDateTime
is a date-time object that has a precision of nanoseconds, and includes the offset from UTC. And the ISO_OFFSET_DATE_TIME
is a standard DateTimeFormatter
format, that understands the Z
designation and sets it as offset 0 from UTC.
The next step is to use this in JDBC, and Oracle says in this article that the java.time
objects should be used with the setObject()
method (rather than setTimeStamp()
). E.g.
stmt.setObject( 1, odt, JDBCType.TIMESTAMP_WITH_TIMEZONE );
Note that this may depend on the database and JDBC driver, which should, of course, be up-to-date.