var interval = 1000; function ShowCountDown(year,month,day,divname) { var now = new Date(); //创建Date类 var endDate = new Date(year, month-1, day); var leftTime=endDate.getTime()-now.getTime(); //计算出指定时间和当前时间的毫秒值 var leftsecond = parseInt(leftTime/1000); //将毫秒值转换为秒值并进行取整 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); //计算出秒数 var cc = document.getElementById(divname); cc.innerHTML = "思鹏博客提醒您距离端午节"+year+"年"+month+"月"+day+"日还有:"+day1+"天"+hour+"小时"+minute+"分"+second+"秒"; } window.setInterval(function(){ShowCountDown(2015,6,20,'divdown1');}, interval); //每隔一秒更新一次时间