多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
***** #### 1、设置时间为当前时间 ``` function setNowTime($){ var data = new Date(); var y = data.getFullYear(); var m = data.getMonth()+1; var d = data.getDate(); var str = ' '+y+'-'+abc(m)+'-'+abc(d)+' '; $.html(str); function abc(obj){ return abc<10?'0'+obj:obj; } } setNowTime($('.times')); ``` #### 2、设置时间为当前时间的多少天后 ``` function zero(obj){ return obj<10?'0'+obj:obj; } function setNextTime(obj, num){ var time = parseInt((new Date()).getTime())+num*24*60*60*1000; var time2 = new Date(time); var y = time2.getFullYear(); var m = time2.getMonth()+1; var d = time2.getDate(); var times = y+'年'+zero(m)+'月'+zero(d)+'日'; obj.html(times); } setNextTime($('.times'), 3); ``` #### 3、设置时间为当前时间的多少天之前 ``` function zero(obj){ return obj<10?'0'+obj:obj; } function setNextTime(obj, num){ var time = parseInt((new Date()).getTime())-num*24*60*60*1000; var time2 = new Date(time); var y = time2.getFullYear(); var m = time2.getMonth()+1; var d = time2.getDate(); var times = y+'年'+zero(m)+'月'+zero(d)+'日'; obj.html(times); } setNextTime($('.times'), 3); ``` #### 4、设置倒计时多少时间 ***** ``` function countdown(time){//传入的值单位为秒 // time = localStorage.getItem('time')?localStorage.getItem('time'):time; if (time<=0) { return false; } var timer = null; var h = Math.floor(time/60/60);//计算多少小时 var m = Math.floor((time - h*60*60)/60);//计算多少分钟 var s = (time - h*60*60 - m * 60)%60;//计算多少秒 $('.hour').html(zero(h)); $('.minute').html(zero(m)); $('.second').html(zero(s)); timer = setInterval(function(){ time--; localStorage.setItem('time',time); var h = Math.floor(time/60/60);//计算多少小时 var m = Math.floor((time - h*60*60)/60);//计算多少分钟 var s = (time - h*60*60 - m * 60)%60;//计算多少秒 $('.hour').html(zero(h)); $('.minute').html(zero(m)); $('.second').html(zero(s)); if(time <= 0){ time = 0; clearInterval(timer); } },1000); } function zero(obj){ return obj<10?'0'+obj:obj; } countdown(3*60*60); ``` 5、 ***** ``` function setNowTime(){ var now_data = new Date(); var now_y = now_data.getFullYear(); var now_m = now_data.getMonth()+1; var now_d = now_data.getDate()+1; var now_str = now_y+'-'+abc(now_m)+'-'+abc(now_d)+' '+'00:00:00'; var datas = new Date(now_str); var next_data = datas.getTime(); var data = new Date(next_data - now_data); countdown($(".countdown"), parseInt(data/1000)); function abc(obj){ return abc<10?'0'+obj:obj; } } ```