js格式化成秒

6945 人参与 | 时间:2024年03月29日 11:01:44
内容
formatSeconds = function(value) {
var theTime = parseInt(value);
var theTime1 = 0;
var theTime2 = 0;
if (theTime > 60) {
theTime1 = parseInt(theTime / 60);
theTime = parseInt(theTime % 60);
if (theTime1 > 60) {
theTime2 = parseInt(theTime1 / 60);
theTime1 = parseInt(theTime1 % 60)
}
}
return {
'hour': theTime2 < 10 ? '0' + theTime2 : theTime2,
'min': theTime1 < 10 ? '0' + theTime1 : theTime1,
'sec': theTime < 10 ? '0' + theTime : theTime
}
};