翊枫
撸码才能成长,学会深究,懂得填坑

获取当前时间

let nowTime ="00:00:00"
let getNowTime = ()=> {
	const now = new Date();
	const hour = now.getHours() < 10 ? '0' + now.getHours() : now.getHours();
	const min = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
	const sec = now.getSeconds() < 10 ? '0' + now.getSeconds() : now.getSeconds();
	nowTime = `${hour}:${min}:${sec}`;
	setTimeout(getNowTime,1000)
}



getNowTime() // 获取当前时间

  

// 写的太low了,再看我都佩服自己了,写的啥玩意

//倒计时

var timer=null;
var interval = 1000; 
function ShowCountDown(year,month,day,hour,minute,second,divname) { 
var cc = document.getElementById(divname); 
var now = new Date(); 
var endDate = new Date(year,month-1,day,hour,minute,second); 
var leftsecond = Math.round((endDate-now)/1000);
if(leftsecond<0){
    clearInterval(timer);
    return;
}else{
    //var day1=parseInt(leftsecond/(24*60*60)); 
    var ofd=parseInt(leftsecond/3600/24);//计算天数
    var ofh=parseInt((leftsecond%(3600*24))/3600);//计算小时
    var ofm=parseInt((leftsecond%3600)/60);//计算分
    var ofs=leftsecond%60;//计算秒
    if (ofd <= 9) ofd = "0" + ofd;
    if (ofh <= 9) ofh = "0" + ofh;
    if (ofm <= 9) ofm = "0" + ofm;
    if (ofs <= 9) ofs = "0" + ofs; 
        cc.innerHTML = ofd+"天"+ofh+"小时"+ofm+"分"+ofs+"秒";
    }
} 
    timer=setInterval(function()        {ShowCountDown(2017,7,10,16,27,10,'divdown1');}, interval);//传入年月日时分秒,通过ID得到存放倒计时的元素    

  

posted on 2017-08-15 10:22  翊枫  阅读(315)  评论(0编辑  收藏  举报

Stick to the code and become the code God.