public static Date parse ( String s ) throws TextParseException { if ( s . length ( ) != 14 ) { throw new TextParseException ( "Invalid time encoding: " + s ) ; } Calendar c = new GregorianCalendar ( TimeZone . getTimeZone ( "UTC" ) ) ; c . clear ( ) ; try { int year = Integer . parseInt ( s . substring ( 0 , 4 ) ) ; int month = Integer . parseInt ( s . substring ( 4 , 6 ) ) - 1 ; int date = Integer . parseInt ( s . substring ( 6 , 8 ) ) ; int hour = Integer . parseInt ( s . substring ( 8 , 10 ) ) ; int minute = Integer . parseInt ( s . substring ( 10 , 12 ) ) ; int second = Integer . parseInt ( s . substring ( 12 , 14 ) ) ; c . set ( year , month , date , hour , minute , second ) ; } catch ( NumberFormatException e ) { throw new TextParseException ( "Invalid time encoding: " + s ) ; } return c . getTime ( ) ; }
Parses a formatted time string into a Date .