public ZonedDateTime getInternalZonedDateTime ( ColumnInformation columnInfo , Class clazz , TimeZone timeZone ) throws SQLException { if ( lastValueWasNull ( ) ) { return null ; } if ( length == 0 ) { lastValueNull |= BIT_LAST_FIELD_NULL ; return null ; } switch ( columnInfo . getColumnType ( ) . getSqlType ( ) ) { case Types . TIMESTAMP : int year = ( ( buf [ pos ] & 0xff ) | ( buf [ pos + 1 ] & 0xff ) << 8 ) ; int month = buf [ pos + 2 ] ; int day = buf [ pos + 3 ] ; int hour = 0 ; int minutes = 0 ; int seconds = 0 ; int microseconds = 0 ; if ( length > 4 ) { hour = buf [ pos + 4 ] ; minutes = buf [ pos + 5 ] ; seconds = buf [ pos + 6 ] ; if ( length > 7 ) { microseconds = ( ( buf [ pos + 7 ] & 0xff ) + ( ( buf [ pos + 8 ] & 0xff ) << 8 ) + ( ( buf [ pos + 9 ] & 0xff ) << 16 ) + ( ( buf [ pos + 10 ] & 0xff ) << 24 ) ) ; } } return ZonedDateTime . of ( year , month , day , hour , minutes , seconds , microseconds * 1000 , timeZone . toZoneId ( ) ) ; case Types . VARCHAR : case Types . LONGVARCHAR : case Types . CHAR : //string conversion String raw = new String ( buf , pos , length , StandardCharsets . UTF_8 ) ; if ( raw . startsWith ( "0000-00-00 00:00:00" ) ) { return null ; } try { return ZonedDateTime . parse ( raw , TEXT_ZONED_DATE_TIME ) ; } catch ( DateTimeParseException dateParserEx ) { throw new SQLException ( raw + " cannot be parse as ZonedDateTime. time must have \"yyyy-MM-dd[T/ ]HH:mm:ss[.S]\" " + "with offset and timezone format (example : '2011-12-03 10:15:30+01:00[Europe/Paris]')" ) ; } default : throw new SQLException ( "Cannot read " + clazz . getName ( ) + " using a " + columnInfo . getColumnType ( ) . getJavaTypeName ( ) + " field" ) ; } }
Get ZonedDateTime from raw binary format .