2012-08-08 105 views
3

每次我怎麼就稱之爲HTML5音頻標記時間

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

它返回我這個

351.234 

我怎樣才能將其轉換爲這種類型的OFR格式分/秒。 3:51秒(我不知道我是否正確與我的時間估計)

+0

如果持續時間351秒,這是不一樣的在3分51秒...... – 2012-08-08 11:08:10

+0

你可能想看看這個 http://stackoverflow.com/questions/4993097/html5-display-audio-當前時間 – 2012-08-08 11:16:26

回答

10

你的意思是你想將其轉換爲min和秒,如果是的話:

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

你可以使用moment.js來做到這一點:

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

結果將是「06:51」。

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

結果將是「06:51.234」。