微信小程序日期增加时间完成订单失效倒计时效果
作者:换日线°
这篇文章主要介绍了微信小程序日期增加时间完成订单失效倒计时效果,在我们日常购物过程中经常会遇到这样的功能,本文通过示例代码给大家详细讲解,需要的朋友参考下吧
效果图
.wxml
<view class="TimeSeond">{{second}}</view>
.js
Page({ data: { tiem_one:'', second:'',//倒计时 deadline:'', }, onLoad(){ this.countdown(); }, countdown(){ let timestamp = Date.parse(new Date()) / 1000;//当前时间戳 let time = this.addtime('2024-4-19 17:20:00');//当前时间转时间戳 if(time > timestamp){ this.deadline = (time - timestamp) * 1000 this.setData({ deadline:this.deadline }) this.single() }else{ that.setData({ second:'00:00' }) } }, addtime(time){ let date = new Date(time); let minutes = date.getMinutes(); date.setMinutes(minutes+30);//增加三十分钟 return Date.parse(date) / 1000; }, single(e){ var that = this var time = that.deadline,minutes,seconds; that.tiem_one = setInterval(function() { time = time - 1000 minutes = parseInt((time % (1000 * 60 * 60)) / (1000 * 60)); seconds = parseInt((time % (1000 * 60)) / 1000); if (time < 1) { that.setData({ second:'00:00' }) clearInterval(that.tiem_one) return false } minutes = minutes > 9 ? minutes : '0' + minutes seconds = seconds > 9 ? seconds : '0' + seconds that.setData({ second:minutes + ':' + seconds }) },1000) }, })
到此这篇关于微信小程序日期增加时间完成订单失效倒计时的文章就介绍到这了,更多相关小程序订单失效倒计时内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!