需求
将秒数转为最大单位为天,最小单位为秒的格式,即将秒转为天时分秒;
如:后端给你的数字是 120000
,单位是秒,将其转为 1天9小时20分0秒
;
function timeStamp( second_time ){
var time = parseInt(second_time) + "秒";
if( parseInt(second_time )> 60){
var second = parseInt(second_time) % 60;
var min = parseInt(second_time / 60);
time = min + "分" + second + "秒";
if( min > 60 ){
min = parseInt(second_time / 60) % 60;
var hour = parseInt( parseInt(second_time / 60) /60 );
time = hour + "小时" + min + "分" + second + "秒";
if( hour > 24 ){
hour = parseInt( parseInt(second_time / 60) /60 ) % 24;
var day = parseInt( parseInt( parseInt(second_time / 60) /60 ) / 24 );
time = day + "天" + hour + "小时" + min + "分" + second + "秒";
}
}
}
return time;
}
timeStamp(120000); // 120000秒,转为 ‘ 1天9小时20分0秒 ’
原文链接:https://blog.csdn.net/he_jiawang/article/details/84807312