js将秒数换算成时分秒

转载自:http://jingyan.baidu.com/article/375c8e19a0413925f2a229d2.html

<script language="javascript">
/**
* 将秒数换成时分秒格式
* 整理:www.jbxue.com
*/
  
function formatSeconds(value) {
    var theTime = parseInt(value);//
    var theTime1 = 0;//
    var theTime2 = 0;// 小时
    if(theTime > 60) {
        theTime1 = parseInt(theTime/60);
        theTime = parseInt(theTime%60);
            if(theTime1 > 60) {
            theTime2 = parseInt(theTime1/60);
            theTime1 = parseInt(theTime1%60);
            }
    }
        var result = ""+parseInt(theTime)+"秒";
        if(theTime1 > 0) {
        result = ""+parseInt(theTime1)+"分"+result;
        }
        if(theTime2 > 0) {
        result = ""+parseInt(theTime2)+"小时"+result;
        }
    return result;
}
</script>
原文地址:https://www.cnblogs.com/zrui-xyu/p/4959498.html