0
点赞
收藏
分享

微信扫一扫

js获取当前时间到凌晨的间隔多少秒,并进行页面刷新

颜路在路上 2022-04-26 阅读 109
前端jquery

方法一

     var timmer = setInterval(function () {
    var curDate = new Date();
    var str = curDate.toTimeString();
    var t= str.substring(0,8);
     if (time == '14:53:40') {
         console.log('after '+time);
         clearInterval(timmer);
         window.location.href ='index';
     }
     }, 1000)

方法二

var date = new Date();
    var now = date.getTime();
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    var t2 = new Date(date.getTime() + 1000 * 60 * 60 * 24);
    var time =t2-now;
    // console.log(time)
    setTimeout(function(){
        window.location.href ='index';
    },time)

 

 

举报

相关推荐

0 条评论