js 解决实时时间刷新精度差不够的问题

vue中使用方法 解决代码如下:

//设置时间
	export default {
		// ....
		//....
		methods:{
			setClock(systime) {
            let that = this;
            clearInterval(this.clockInterval);
            //设置时间循环,每一秒钟循环一次
            let lastTime = null; //
            let localTime = this.$moment().valueOf();
            let delayTime = null;

            this.clockInterval = setInterval(() => {
                //本地时间
                let now = this.$moment().valueOf();
                if (lastTime != null) {
                    delayTime = now - localTime;
                    lastTime += delayTime;
                    localTime = now;
                } else {
                    lastTime = this.$moment(systime).valueOf();
                }
                //设置时钟
                //秒针
           
                this.clocks.bg = this.$moment(lastTime).second() * 6;
                this.clocks.hour = this.$moment(lastTime).hour() * 30;
                this.clocks.minute = this.$moment(lastTime).minute() * 6;
                this.clocks.text = this.$moment(lastTime).format("HH:mm:ss");
                this.clocks.date =
                    this.$moment(lastTime).format("YYYY/MM/DD · dddd");
                //如果是跨天,需要重新获取数据
                let differentDay = false;
                if(!(new Date(this.systemTime).toDateString() === new Date(lastTime).toDateString())){
                    differentDay = true;
                }
                this.systemTime = lastTime;
                if(differentDay){
                    // that.getConferences(
                    //    that.device.roomKey,
                    //    that.device.secret,
                    //     false
                    //);
                }
                // this.setMetting();
                // this.pageChange();
            }, 1000);
        }
		}
        
     }
```
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值