Reputation: 16117
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)
Upvotes: 4
Views: 3743
Reputation: 993
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".
Upvotes: 0
Reputation: 100175
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
Upvotes: 11