倒计时 时分秒数值小于10时给数值前面加0
当时分秒数值小于10的时候在时分秒前面添加0怎么弄?
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>限时抢</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
.content3{
width:400px;
height: 100px;
margin:0 auto;
background:#F9263E;
text-align: center;
line-height: 100px;
border-radius: 20px;
}
</style>
</head>
<body>
<div>
<div>还剩: <span id="LeftTime"></span></div>
</div>
</body>
<script type="text/javascript">
window.onload = function(){
showTime();
}
function showTime(){
var endTime = new Date("2017/4/20,12:00:00");
var startTime = new Date();
var leftSeconds = parseInt((endTime.getTime()-startTime.getTime())/1000);//两个时间点之间的秒数
var d = parseInt(leftSeconds/(60*60*24));//天数,这个直接取整
var h = parseInt(leftSeconds/3600)%24;//小时需要求余24,获取天数之外的小时数
var m = parseInt(leftSeconds/60)%60;//只获取残留的分钟数
var s = leftSeconds%60;//残留的秒数
if(leftSeconds<=0){
document.getElementById("LeftTime").innerHTML="团购已结束";
}else{
document.getElementById("LeftTime").innerHTML=d+"天"+h+"小时"+m+"分"+ s+"秒";
setTimeout(showTime,1000);
}
}
</script>
</html>