js将秒转换为日时分秒

参数s:时间秒

function secondsFormat( s ) { 
    var day = Math.floor( s/ (24*3600) ); // Math.floor()向下取整 
    var hour = Math.floor( (s - day*24*3600) / 3600); 
    var minute = Math.floor( (s - day*24*3600 - hour*3600) /60 ); 
    var second = s - day*24*3600 - hour*3600 - minute*60; 
    return day + "天"  + hour + "时" + minute + "分" + second + "秒"; 
}
console.log(secondsFormat(5555555)) // 64天7时12分35秒
console.log(secondsFormat(1234))  // 0天0时20分34秒
发布了36 篇原创文章 · 获赞 6 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/uperficialyu/article/details/87931461