public Object toObject ( String pString , Class pType , String pFormat ) throws ConversionException { if ( StringUtil . isEmpty ( pString ) ) return null ; try { DateFormat format ; if ( pFormat == null ) { // Use system default format, using default locale format = DateFormat . getDateTimeInstance ( ) ; } else { // Get format from cache format = getDateFormat ( pFormat ) ; } Date date = StringUtil . toDate ( pString , format ) ; // Allow for conversion to Date subclasses (ie. java.sql.*) if ( pType != Date . class ) { try { date = ( Date ) BeanUtil . createInstance ( pType , new Long ( date . getTime ( ) ) ) ; } catch ( ClassCastException e ) { throw new TypeMismathException ( pType ) ; } catch ( InvocationTargetException e ) { throw new ConversionException ( e ) ; } } return date ; } catch ( RuntimeException rte ) { throw new ConversionException ( rte ) ; } }
Converts the string to a date using the given format for parsing .