js中關於時間的轉化——將秒/毫秒轉化成xx小時xx分鐘xx秒
轉載出處:https://blog.csdn.net/ch5256865/article/details/52084484
//將毫秒秒轉化為xx小時xx分鐘xx秒
function MillisecondToDate(msd) {
var time = parseFloat(msd) / 1000; //先將毫秒轉化成秒
if (null != time && "" != time) {
if (time > 60 && time < 60 * 60) {
time = parseInt(time / 60.0) + "分鐘" + parseInt((parseFloat(time / 60.0) -
parseInt(time / 60.0)) * 60) + "秒";
}
else if (time >= 60 * 60 && time < 60 * 60 * 24) {
time = parseInt(time / 3600.0) + "小時" + parseInt((parseFloat(time / 3600.0) -
parseInt(time / 3600.0)) * 60) + "分鐘" +
parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "秒";
}
else {
time = parseInt(time) + "秒";
}
}
return time;
}
用法:
jquery+js
$("#totalTime").text(MillisecondToDate(totalTime));//totalTime單位為秒