2012-09-01 8 views
6

미디어가 재생되는 동안 시간을 ​​계산하는 시간 함수를 만들었습니다. 선행 0을 표시하지 않습니다. 앞에 0을 표시하려면 어떻게합니까?어떻게 앞에 오는 0으로 시간을 표시 할 수 있습니까?

function converttoTime(timeInSeconds) 
    { 
    var minutes = Math.round(Math.floor(timeInSeconds/60)); 
    var seconds = Math.round(timeInSeconds - minutes * 60); 
    //var hours = Math.round(Math.floor(timeInSeconds/3600)); 
    //time = time - hours * 3600; 
    var time=minutes+':'+seconds; 
    return time; 
    } 

답변

31

이 작동합니다 :

var time=('0' + minutes).slice(-2)+':'+('0' + seconds).slice(-2); 
관련 문제