固定时间倒计时

时间:2022-12-04 22:03:58

var year
var month
var date1
function endTime(){
myDate = new Date();
year = myDate.getFullYear();
month = myDate.getMonth()+1;
date1 =myDate.getDate();
if(month < 10) {
month = '0' + month;
}
if(date1 < 10) {
date1 = '0' + date1;
}

return year + '/'+ month + '/' + date1 + ' ' + '20:45';


}

setInterval(function(){
// 当前时间
var nowtime = Date.parse(new Date());
// console.log(nowtime);
// 结束时间
var end = endTime();
var date = new Date(end);
var endtime = date.getTime();
// 倒计时时间
var leftTime = endtime - nowtime;
var leftsecond = parseInt(leftTime/1000);
//console.log(leftTime)
var day1=Math.floor(leftsecond/(60*60*24));
var hour=Math.floor((leftsecond-day1*24*60*60)/3600);
var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
console.log("距离"+year+"年"+month+"月"+date1+"日20时45分还有:"+day1+"天"+hour+"小时"+minute+"分"+second+"秒")

},1000);