convert time string format
<p>I want to convert a almost any kind of time format to the format <code>HH:mm:ss</code> in javacript.
I've got problem with the commented below.</p>

<pre><code>function parseTime(timeString){

    var timeString = timeString.toLowerCase();
    timeString = $.trim(timeString);

    var regEx = /^([0-9]|1[0-9]|2[0-3])$/;
    var regEx2 = /^([0-9]|1[0-9]|2[0-3])\.?([0-5][0-9])$/;
    var regEx3 = /^([0-9]|1[0-2])(a|p|am|pm)$/;
    var regEx4 = /^([1-9]|10|11|12)\.?([0-5][0-9])(a|p|am|pm)$/;

    if(regEx.test(timeString)){
        var hours = timeString;
        if(hours.length == 1){
            hours = '0' + hours;
        }
        return hours + ':00:00';
    }
    else if(regEx2.test(timeString)){
        var hoursEndIndex, minutesStartIndex;
        if(timeString.indexOf('.')){
            hoursEndIndex = timeString.indexOf('.');
            minutesStartIndex = timeString.indexOf('.') + 1;
        }else if(timeString.length == 3){//Problem here timeString.length returns 3 but the code below isn't executed?
            hoursEndIndex = 1;
            minutesStartIndex = 1;
        }else if(timeString.length == 4){//Same thing here?
            hoursEndIndex = 2;
            minutesStartIndex = 2;
            return timeString.length;
        }
        var hours = timeString.substring(0, hoursEndIndex);
        if(hours.length == 1){
            hours = '0' + hours;
        }
        var minutes = timeString.substr(minutesStartIndex, 2);
        return hours + ':' + minutes + ':00';
    }
</code></pre>
