H5页面定时器

来源:互联网 发布:现在常用的数据库 编辑:程序博客网 时间:2024/06/03 18:51

做活动时,需要的定时器js写法

 function checkedTime(){    var startTime = new Date().formatTimestamp('2017-12-25 00:00:00');    var endTime = new Date().formatTimestamp('2018-01-05 23:59:59');    var nowTime = new Date().getTime();    if(nowTime < startTime) {        layer.open({            content:'<div style="line-height:1.5;"><p style="color:#fff;font-size:0.6rem;">活动未开始!</p>'+            '<p style="color:#fff;font-size:0.5rem;">活动时间:2017-12-25~2018-12-05</p></div>'        });        return false;    }else if(nowTime > endTime) {        layer.open({            content:'<div style="line-height:1.5;"><p style="color:#fff;font-size:0.6rem;">活动已结束!</p>'+            '<p style="color:#fff;font-size:0.5rem;">活动时间:2017-12-25~2018-12-05</p></div>'        });        return false;    }    return true;}//将字符串时间格式化成13位时间戳Date.prototype.formatTimestamp = function (val) {    var f = val.split(' ', 2);    var d = (f[0] ? f[0] : '').split('-', 3);    var t = (f[1] ? f[1] : '').split(':', 3);    return (new Date(        parseInt(d[0], 10) || null,        (parseInt(d[1], 10) || 1) - 1,        parseInt(d[2], 10) || null,        parseInt(t[0], 10) || null,        parseInt(t[1], 10) || null,        parseInt(t[2], 10) || null    )).getTime();};


原创粉丝点击