public Time getInternalTime ( ColumnInformation columnInfo , Calendar cal , TimeZone timeZone ) throws SQLException { if ( lastValueWasNull ( ) ) { return null ; } if ( columnInfo . getColumnType ( ) == ColumnType . TIMESTAMP || columnInfo . getColumnType ( ) == ColumnType . DATETIME ) { Timestamp timestamp = getInternalTimestamp ( columnInfo , cal , timeZone ) ; return ( timestamp == null ) ? null : new Time ( timestamp . getTime ( ) ) ; } else if ( columnInfo . getColumnType ( ) == ColumnType . DATE ) { throw new SQLException ( "Cannot read Time using a Types.DATE field" ) ; } else { String raw = new String ( buf , pos , length , StandardCharsets . UTF_8 ) ; if ( ! options . useLegacyDatetimeCode && ( raw . startsWith ( "-" ) || raw . split ( ":" ) . length != 3 || raw . indexOf ( ":" ) > 3 ) ) { throw new SQLException ( "Time format \"" + raw + "\" incorrect, must be HH:mm:ss" ) ; } boolean negate = raw . startsWith ( "-" ) ; if ( negate ) { raw = raw . substring ( 1 ) ; } String [ ] rawPart = raw . split ( ":" ) ; if ( rawPart . length == 3 ) { int hour = Integer . parseInt ( rawPart [ 0 ] ) ; int minutes = Integer . parseInt ( rawPart [ 1 ] ) ; int seconds = Integer . parseInt ( rawPart [ 2 ] . substring ( 0 , 2 ) ) ; Calendar calendar = Calendar . getInstance ( ) ; if ( options . useLegacyDatetimeCode ) { calendar . setLenient ( true ) ; } calendar . clear ( ) ; calendar . set ( 1970 , Calendar . JANUARY , 1 , ( negate ? - 1 : 1 ) * hour , minutes , seconds ) ; int nanoseconds = extractNanos ( raw ) ; calendar . set ( Calendar . MILLISECOND , nanoseconds / 1000000 ) ; return new Time ( calendar . getTimeInMillis ( ) ) ; } else { throw new SQLException ( raw + " cannot be parse as time. time must have \"99:99:99\" format" ) ; } } }
Get time from raw text format .