秒数转换为天时分秒
function formartSecToStr(seconds){
let daySec = 24 * 60 * 60;
let hourSec = 60 * 60;
let minuteSec = 60;
let dd = Math.floor(seconds / daySec);
let hh = Math.floor((seconds % daySec) / hourSec );
let mm = Math.floor((seconds % hourSec) / minuteSec);
let ss = seconds % minuteSec;
if(dd > 0){
return dd + '天' + hh + '小时' + mm + '分钟' + ss + '秒';
}else if(hh > 0){
return hh + '小时' + mm + '分钟' + ss + '秒';
}else if(mm > 0){
return mm + '分钟' + ss + '秒';
}else{
return ss + '秒';
}
}
console.log(formartSecToStr(20));
console.log(formartSecToStr(61));
console.log(formartSecToStr(3661));
console.log(formartSecToStr(86361));
console.log(formartSecToStr(86661));