突然想到的
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>js倒计时</title>
</head>
<body>
<div id="newdata"></div>
<div id="olddata"></div>
</body>
</html>
<script>
function show(){
setInterval(function(){
var odata = new Date();
var oyears = odata.getFullYear();
var omonth = odata.getMonth()+1;
var oday = odata.getDate();
var ohours = odata.getHours();
var ominutes = odata.getMinutes();
var oseconds = odata.getSeconds();
//时间表
document.getElementById('newdata').innerHTML = oyears +'-'+ omonth+'-'+oday+' '+ohours+':'+ominutes+':'+oseconds ;
//倒计时
var amonth = 12-omonth;
// var arr = new Array(); 本来打算把每月的天数存放到数组里
var days = 0;
if(omonth == 1||omonth == 3||omonth == 5||omonth == 7||omonth ==8||omonth == 10||omonth == 12){
days = 31;
}else if(omonth == 2){
if(oyears%4 == 0&&oyears%100!=0&&oyears%400==0){ //四年一闰百年不闰四百年又闰
days = 29;
}else{
days =28;
}
}else{
days = 30;
}
var aday = days-oday;
var ahours = 24-ohours;
var amintes = 60-ominutes;
var aseconds = 60-oseconds;
document.getElementById('olddata').innerHTML = '倒计时:'+oyears +'年还剩'+ amonth+'个月'+aday+'天'+ahours+'小时'+amintes+'分钟'+aseconds +'秒';
},1000);
}
show();
</script>