4

How come each time I call the

var track_length = $(".audio-player")[counter].duration;

it returns me this

351.234

How can I convert it to this type ofr Format minutes/seconds. 3:51 seconds ?(I am not sure if I am correct with my estimation of the time)

2

2 Answers 2

11

Do you mean you want to convert it to min and secs, if yes then:

function readableDuration(seconds) {
    sec = Math.floor( seconds );    
    min = Math.floor( sec / 60 );
    min = min >= 10 ? min : '0' + min;    
    sec = Math.floor( sec % 60 );
    sec = sec >= 10 ? sec : '0' + sec;    
    return min + ':' + sec;
}
console.log( readableDuration(351.234) ); // 05:51
0

You can use moment.js to do it:

moment.utc(this.duration * 1000).format("mm:ss");

The result will be "06:51".

moment.utc(this.duration * 1000).format("mm:ss.SSS");

The result will be "06:51.234".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.