public static int parseDurationString(String timeStr) {
        int seconds = 0;
        Matcher matcher = timeStringPattern.matcher(timeStr);
        while (matcher.find()) {
            String s = matcher.group();
            String[] parts = s.split("(?<=[yMwdhms])(?=\\d)|(?<=\\d)(?=[yMwdhms])");
            int numb = Integer.parseInt(parts[0]);
            String type = parts[1];
            switch (type) {
                case "s":
                    seconds = seconds + (numb);
                    break;
                case "m":
                    seconds = seconds + (numb * 60);
                    break;
                case "h":
                    seconds = seconds + (numb * 60 * 60);
                    break;
                case "d":
                    seconds = seconds + (numb * 60 * 60 * 24);
                    break;
                case "w":
                    seconds = seconds + (numb * 60 * 60 * 24 * 7);
                    break;
                case "M":
                    seconds = seconds + (numb * 60 * 60 * 24 * 30);
                    break;
                case "y":
                    seconds = seconds + (numb * 60 * 60 * 24 * 365);
                    break;
                default:
            }
        }
        return seconds;
    }
public static int parseDurationString ( String timeStr ) { int seconds = 0 ; Matcher matcher = timeStringPattern . matcher ( timeStr ) ; while ( matcher . find ( ) ) { String s = matcher . group ( ) ; String [ ] parts = s . split ( "(?<=[yMwdhms])(?=\\d)|(?<=\\d)(?=[yMwdhms])" ) ; int numb = Integer . parseInt ( parts [ 0 ] ) ; String type = parts [ 1 ] ; switch ( type ) { case "s" : seconds = seconds + ( numb ) ; break ; case "m" : seconds = seconds + ( numb * 60 ) ; break ; case "h" : seconds = seconds + ( numb * 60 * 60 ) ; break ; case "d" : seconds = seconds + ( numb * 60 * 60 * 24 ) ; break ; case "w" : seconds = seconds + ( numb * 60 * 60 * 24 * 7 ) ; break ; case "M" : seconds = seconds + ( numb * 60 * 60 * 24 * 30 ) ; break ; case "y" : seconds = seconds + ( numb * 60 * 60 * 24 * 365 ) ; break ; default : } } return seconds ; }
parseToSeconds duration string like 'nYnMnDnHnMnS' to seconds

@param timeStr duration string like 'nYnMnDnHnMnS'
@return duration in seconds