public static Date formatStringToDate(String argDateStr, String argFormat) throws Exception {
        if (argDateStr == null || argDateStr.trim().length() < 1) {
            throw new Exception("参数[日期]不能为空!");
        }
        String strFormat = argFormat;
        if (strFormat == null || strFormat.length() == 0) {
            strFormat = Y_M_D;
            if (argDateStr.length() > 16) {
                strFormat = Y_M_D_HMS;
            } else if (argDateStr.length() > 10) {
                strFormat = Y_M_D_HM;
            }
        }
        SimpleDateFormat sdfFormat = new SimpleDateFormat(strFormat);
        //严格模式
        sdfFormat.setLenient(false);
        try {
            return sdfFormat.parse(argDateStr);
        } catch (ParseException e) {
            throw new Exception(e);
        }
    }
public static Date formatStringToDate ( String argDateStr , String argFormat ) throws Exception { if ( argDateStr == null || argDateStr . trim ( ) . length ( ) < 1 ) { throw new Exception ( "参数[日期]不能为空!" ) ; } String strFormat = argFormat ; if ( strFormat == null || strFormat . length ( ) == 0 ) { strFormat = Y_M_D ; if ( argDateStr . length ( ) > 16 ) { strFormat = Y_M_D_HMS ; } else if ( argDateStr . length ( ) > 10 ) { strFormat = Y_M_D_HM ; } } SimpleDateFormat sdfFormat = new SimpleDateFormat ( strFormat ) ; sdfFormat . setLenient ( false ) ; try { return sdfFormat . parse ( argDateStr ) ; } catch ( ParseException e ) { throw new Exception ( e ) ; } }
把字符串格式化成日期

@param argDateStr
@param argFormat
@return