直接贴代码。
function mathTime(ms){
var sec = ms/1000;
var min = sec/60;
if(min>=1){
var h = min/60;
if(h>=1){
var d = h/24;
if(d>=1){
var m = d/30.5;
if(m>=1){
var y = m/12;
if(y>=1){
return Math.floor(y)+"年"+Math.floor(sec%31622400/2635200)+"月"+Math.floor(sec%2635200/86400)+"天"+Math.floor(sec%86400/3600)+"小时"+Math.floor(sec%3600/60)+"分"+Math.floor(sec%60)+"秒";
}else{
return Math.floor(m)+"月"+Math.floor(sec%2635200/86400)+"天"+Math.floor(sec%86400/3600)+"小时"+Math.floor(sec%3600/60)+"分"+Math.floor(sec%60)+"秒";
}
}else{
return Math.floor(d)+"天"+Math.floor(sec%86400/3600)+"小时"+Math.floor(sec%3600/60)+"分"+Math.floor(sec%60)+"秒";
}
}else{
return Math.floor(h)+"小时"+Math.floor(sec%3600/60)+"分"+Math.floor(sec%60)+"秒";
}
}else{
return tim = Math.floor(min)+"分"+Math.floor(sec%60)+"秒";
}
}else{
return sec+"秒";
}
}