您的位置:首页 > Web前端 > JavaScript

js格式化秒数

2017-04-19 14:41 103 查看
function formatTime(value)
{  

 var theTime = parseInt(value);// 秒

    var theTime1
= 0;// 分

    var theTime2
= 0;// 小时

    if(theTime
> 60) {

       
theTime1 = parseInt(theTime/60);

       
theTime = parseInt(theTime`);

       
if(theTime1 > 60) {

       
theTime2 = parseInt(theTime1/60);

       
theTime1 = parseInt(theTime1`);

       
}

    }

    var result =
"";

    if(theTime
> 0){

   
 result = ""+parseInt(theTime)+"秒";

    }

    if(theTime1
> 0) {

   
 result = ""+parseInt(theTime1)+"分"+result;

    }

    if(theTime2
> 0) {

   
 result = ""+parseInt(theTime2)+"小时"+result;

    }

    return
result;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: