public long getDurationMillis(Object object) {
        // parse here because duration could be bigger than the int supported
        // by the period parser
        String original = (String) object;
        String str = original;
        int len = str.length();
        if (len >= 4 &&
            (str.charAt(0) == 'P' || str.charAt(0) == 'p') &&
            (str.charAt(1) == 'T' || str.charAt(1) == 't') &&
            (str.charAt(len - 1) == 'S' || str.charAt(len - 1) == 's')) {
            // ok
        } else {
            throw new IllegalArgumentException("Invalid format: \"" + original + '"');
        }
        str = str.substring(2, len - 1);
        int dot = -1;
        boolean negative = false;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
                // ok
            } else if (i == 0 && str.charAt(0) == '-') {
                // ok
                negative = true;
            } else if (i > (negative ? 1 : 0) && str.charAt(i) == '.' && dot == -1) {
                // ok
                dot = i;
            } else {
                throw new IllegalArgumentException("Invalid format: \"" + original + '"');
            }
        }
        long millis = 0, seconds = 0;
        int firstDigit = negative ? 1 : 0;
        if (dot > 0) {
            seconds = Long.parseLong(str.substring(firstDigit, dot));
            str = str.substring(dot + 1);
            if (str.length() != 3) {
                str = (str + "000").substring(0, 3);
            }
            millis = Integer.parseInt(str);
        } else if (negative) {
            seconds = Long.parseLong(str.substring(firstDigit, str.length()));
        } else {
            seconds = Long.parseLong(str);
        }
        if (negative) {
            return FieldUtils.safeAdd(FieldUtils.safeMultiply(-seconds, 1000), -millis);
        } else {
            return FieldUtils.safeAdd(FieldUtils.safeMultiply(seconds, 1000), millis);
        }
    }
public long getDurationMillis ( Object object ) { String original = ( String ) object ; String str = original ; int len = str . length ( ) ; if ( len >= 4 && ( str . charAt ( 0 ) == 'P' || str . charAt ( 0 ) == 'p' ) && ( str . charAt ( 1 ) == 'T' || str . charAt ( 1 ) == 't' ) && ( str . charAt ( len - 1 ) == 'S' || str . charAt ( len - 1 ) == 's' ) ) { } else { throw new IllegalArgumentException ( "Invalid format: \"" + original + '"' ) ; } str = str . substring ( 2 , len - 1 ) ; int dot = - 1 ; boolean negative = false ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) >= '0' && str . charAt ( i ) <= '9' ) { } else if ( i == 0 && str . charAt ( 0 ) == '-' ) { negative = true ; } else if ( i > ( negative ? 1 : 0 ) && str . charAt ( i ) == '.' && dot == - 1 ) { dot = i ; } else { throw new IllegalArgumentException ( "Invalid format: \"" + original + '"' ) ; } } long millis = 0 , seconds = 0 ; int firstDigit = negative ? 1 : 0 ; if ( dot > 0 ) { seconds = Long . parseLong ( str . substring ( firstDigit , dot ) ) ; str = str . substring ( dot + 1 ) ; if ( str . length ( ) != 3 ) { str = ( str + "000" ) . substring ( 0 , 3 ) ; } millis = Integer . parseInt ( str ) ; } else if ( negative ) { seconds = Long . parseLong ( str . substring ( firstDigit , str . length ( ) ) ) ; } else { seconds = Long . parseLong ( str ) ; } if ( negative ) { return FieldUtils . safeAdd ( FieldUtils . safeMultiply ( - seconds , 1000 ) , - millis ) ; } else { return FieldUtils . safeAdd ( FieldUtils . safeMultiply ( seconds , 1000 ) , millis ) ; } }
Gets the duration of the string using the standard type.
This matches the toString() method of ReadableDuration.

@param object  the String to convert, must not be null
@throws ClassCastException if the object is invalid