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)

user962206
  • 15,637
  • 61
  • 177
  • 270

2 Answers2

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
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
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".

Calvin
  • 953
  • 1
  • 9
  • 16