效果描述:结束时间设置为2017/12/512:20:12
具体代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>限时抢</title>
<script language="JavaScript" type="text/javascript">
window.onload = function () {
showTime();
}
function showTime() {
var curtime = new Date();
var endtime = new Date("2017/12/5,12:20:12");
var lefttime =parseInt((endtime.getTime() - curtime.getTime())/1000);
var d =parseInt(lefttime/(24*60*60));
var h = parseInt(lefttime/(60*60)%24);
var m = parseInt(lefttime/60%60);
var s = parseInt(lefttime%60);
document.getElementById('leftTime').innerHTML = d+'天'+h+'小时'+m+'分'+s+'秒';
if (lefttime<=0){
document.getElementById('leftTime').innerHTML = '团购结束';//如果时间超过了就显示团购结束
}
//alert(s);
setTimeout(showTime,500);
}
</script>
</head>
<body>
<div class="time">还剩<span id="leftTime"></span></div>
</body>
</html>