TL;DR
org.threeten.bp.OffsetDateTime odt =
OffsetDateTime.parse(
"2012-02-12T09:08:13.123456-0400",
org.threeten.bp.format.DateTimeFormatter.ofPattern( "yyyy-MM-dd'T'HH:mm:ssZ" ) // Specify pattern as workaround for Java 8 bug in failing to parse if optional colon is not present.
)
;
java.time
, , , , java.time.
java.time , java.sql.Timestamp. JDBC JDBC 4.2 , java.time.
Instant
Instant UTC ( (9) ). , java.sql.Timestamp, , .
Instant instant = myResultSet.getObject( … , Instant.class ) ;
instant.toString(): 2012-02-12T13: 08: 13.123456Z
ZonedDateTime
, ZoneId, ZonedDateTime.
ZoneId z = ZoneId.of( "America/St_Thomas" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;
zdt.toString(): 2012-02-12T09: 08: 13.123456-04: 00 [America/St_Thomas]
OffsetDateTime
, 2012-02-12T09:08:13.123456-0400 , OffsetDateTime.
continent/region , , , (DST). , OffsetDateTime, ZonedDateTime.
OffsetDateTime odt = OffsetDateTime.parse( "2012-02-12T09:08:13.123456-0400" ) ;
, , Java 8 , COLON . , -04:00 Java 8 , -0400. Java 9. ISO 8601 , java.time. . , , - , .
Java 9, , , .
OffsetDateTime odt =
OffsetDateTime.parse(
"2012-02-12T09:08:13.123456-0400",
DateTimeFormatter.ofPattern( "yyyy-MM-dd'T'HH:mm:ssZ" ) // Specify pattern as workaround for Java 8 bug in failing to parse if optional colon is not present.
)
;
JDBC- JDBC 4.2, java.sql.Timestamp, . java.time, , .
java.sql.Timestamp ts = myResultSet.getTimestamp( … ) ;
Instant instant = ts.toInstant();
- java.time. - , Instant java.sql.Timestamp.
myPreparedStatement.setTimestamp( … , java.sql.Timestamp.from( instant ) ) ;
Java 6 7
Java 6 7 - , java.time . ThreeTen-Backport. , . .
Java 7 JDBC 4.2. , java.time JDBC. , java.sql.Timestamp Instant. DateTimeUtils.toInstant(Timestamp sqlTimestamp) DateTimeUtils.toSqlTimestamp(Instant instant).
java.sql.Timestamp ts = myResultSet.getTimestamp( … ) ;
Instant instant = DateTimeUtils.toInstant( ts ) ;
... ...
java.sql.Timestamp ts = DateTimeUtils.toSqlTimestamp( instant ) ;
myPreparedStatement.setTimestamp( … , ts ) ;
java.time
java.time Java 8 . legacy , java.util.Date, Calendar SimpleDateFormat.
Joda-Time, , java.time.
, . Oracle. Qaru . JSR 310.
java.time?
ThreeTen-Extra java.time . java.time. , Interval, YearWeek, YearQuarter .