首页 > 代码库 > javascript写定时器

javascript写定时器


function time(year,month,day,hours,minuse,miao)
{
var now = new Date();
var endDate = new Date(year, month-1, day,hours,minuse,miao);
var leftTime=endDate.getTime()-now.getTime();
var leftsecond = parseInt(leftTime/1000);
var day=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(day+"天"+hours+"小时"+minutes+"分"+second+"秒")
}
var xx=window.setInterval(function(){ShowCountDown(ys,ms,ds,hs,fs,ss);}, 1000);

getTime()获取1970/01/01 至指定日期的毫秒数;
Math.floor向下取整;

javascript写定时器