我的程序得到一个秒数返回值:60000
如何用JS将他转为:X时:X分:X秒 的这种格式
------解决方案--------------------
//时间秒数格式化
function arrive_timer_format(s) {
var t;
if(s > -1){
hour = Math.floor(s/3600);
min = Math.floor(s/60) % 60;
sec = s % 60;
day = parseInt(hour / 24);
if (day > 0) {
hour = hour - 24 * day;
t = day + "day " + hour + ":";
}
else t = hour + ":";
if(min < 10){t += "0";}
t += min + ":";
if(sec < 10){t += "0";}
t += sec;
}
return t;
}
------解决方案--------------------
- JScript code
function formatTime(second) { return [parseInt(second / 60 / 60), second / 60 % 60, second % 60].join(":") .replace(/\b(\d)\b/g, "0$1"); } alert(formatTime(6000));