this.timer = setInterval(() => { this.countDown() }, 1000); var time="2023-02-21 14:14:49"; //下单时间 var to = new Date(time.replace(/-/g, "/")); var now = new Date(); // 乘以15分钟-计算15分钟倒计时 var deltaTime = to.getTime() + 15 * 60 * 1000 - now.getTime(); // alert(deltaTime) //超时就停止倒计时-操作某些事件 if (deltaTime <= 0) { this.dataForm.orderAccepting = 4; window.clearInterval(this.timer); return; } var d= deltaTime / (1000 * 60 * 60 * 24); var h = Math.floor(deltaTime / 1000 / 60 / 60 % 24); var m = Math.floor(deltaTime / 1000 / 60 % 60); var s = Math.floor(deltaTime / 1000 % 60); //把时间的数字转成字符串, 如果时分秒不足10, 则前面补0 // var timeStr = ""+ (h/10>=1?h=h:h="0"+h) + (m/10>=1?m=m:m="0"+m) + (s/10>=1?s=s:s="0"+s); var timeStr = ""+ (m/10>=1?m=m:m="0"+m) + (s/10>=1?s=s:s="0"+s); // console.log(timeStr,'55555'); this.minute = timeStr.substring(0, 2); this.sec = timeStr.substring(2, 4);