0 775

把毫秒转化成天时分秒,首先我们要明白一点1秒等于多少毫秒,1分等于多少秒

1秒等于1000毫秒

1分等于60秒,1小时等于60分,1天等于24小时。

function formatDuring(mss) {
    var days = parseInt(mss / (1000 * 60 * 60 * 24));
    var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = (mss % (1000 * 60)) / 1000;
    var str = '';
    if(days){
   str = days+ ':';
    }
    if(hours){
  str = str + 'hours:';
    }
    if(minutes == 0){
   minutes = '00';
    }else if(minutes < 10){
   minutes = '0' + minutes;
    }
    str = str + minutes+':';
    seconds = seconds.toFixed(0) * 1;
    if(seconds == 0){
    seconds = '00';
    }else if(seconds < 10){
   seconds = '0' + seconds;
   }
    str = str + seconds;
    return str;
}

代码预览 29000毫秒等于多少直接打印


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>时间格式化</title>
</head>
<body>
<script>
function formatDuring(mss) {
    var days = parseInt(mss / (1000 * 60 * 60 * 24));
    var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = (mss % (1000 * 60)) / 1000;
    var str = '';
    if(days){
	   str = days+ ':';
    }
    if(hours){
	  str = str + 'hours:';
    }
    if(minutes == 0){
	   minutes = '00';
    }else if(minutes < 10){
	   minutes = '0' + minutes;
    }
    str = str + minutes+':';
    seconds = seconds.toFixed(0) * 1;
    if(seconds == 0){
	    seconds = '00';
    }else if(seconds < 10){
	   seconds = '0' + seconds;
   }
    str = str + seconds;
    return str;
}
var data = 29000;
alert(formatDuring(data));
</script>
</body>
</html>


[分类]
[来源] http://erlangyun.com/p/id/175.html
[声明] 本站资源来自用户分享,如损害你的权益请联系客服QQ:120074275给予处理。