TL; DR
OffsetDateTime odt = OffsetDateTime.parse ( "2016-08-18 14:27:15.103+02" , DateTimeFormatter.ofPattern ( "yyyy-MM-dd HH:mm:ss.SSSX" ) ) ;
More details
greg-449 ( ), .
LocalDateTime, -UTC. A LocalDateTime , , .
+02 offset-from-UTC, " UTC ". , UTC 12 , 2 , 14 . . - , LocalDateTime, OffsetDateTime.
SQL, ISO 8601. SPACE T. java.time ISO 8601, .
String input = "2016-08-18 14:27:15.103+02";
String inputModified = input.replace ( " " , "T" );
, Java 8 , , . Java 9. Java 8 .
// Workaround for Java 8 where 2-digit offset fails parsing. Fixed in Java 9.
int lengthOfAbbreviatedOffset = 3;
if ( inputModified.indexOf ( "+" ) == ( inputModified.length () - lengthOfAbbreviatedOffset ) ) {
// If third character from end is a PLUS SIGN, append ':00'.
inputModified = inputModified + ":00";
}
if ( inputModified.indexOf ( "-" ) == ( inputModified.length () - lengthOfAbbreviatedOffset ) ) {
// If third character from end is a PLUS SIGN, append ':00'.
inputModified = inputModified + ":00";
}
.
OffsetDateTime odt = OffsetDateTime.parse ( inputModified );
. , +02 +02:00.
System.out.println ( "input: " + input + " | inputModified: " + inputModified + " | odt: " + odt );
: 2016-08-18 14: 27: 15.103 + 02 | inputModified: 2016-08-18T14: 27: 15.103 + 02: 00 | odt: 2016-08-18T14: 27: 15.103 + 02: 00
. - .
DateTimeFormatter f = DateTimeFormatter.ofPattern ( "yyyy-MM-dd HH:mm:ss.SSSX" );
OffsetDateTime odt = OffsetDateTime.parse ( input , f );
Postgres, , .
JDBC- JDBC 4.2, ResultSet::getObject, Instant OffsetDateTime. , ResultSet::getTimestamp, java.sql.Timestamp, java.time, toInstant Timestamp.
java.time -; java.sql .