微信小程序实现倒计时功能-微信群倒计时编辑器-小程序倒计时功能
1.
在商城商品信息里,会有倒计时的功能
2.计算时间需要转化为时间戳,但是安卓和ios系统对于识别的时间格式是不一样的,安卓对识别没有要求。IOS格式要求2018/08/2010:20:32,使用Date.parse()转化时间戳不会出现在IOS端无法倒计时。
timeFormat:function(param){//小于10的格式化函数returnparam10?'0'+param:param;},countDown:function(){//倒计时函数//获取当前时间,同时得到活动结束时间数组letnewTimeDate.parse(newDate());letendTimeListthis.data.actEndTimeList;letcountDownArr[];//对结束时间进行处理渲染到页面endTimeList.forEach(o{varstrtimeo.replace(/-/g,'/');strtimestrtime.substring(0,19);letendTimenewDate(strtime).getTime();letobjnull;//如果活动未结束,对时间进行处理if(endTime-newTime0){lettime(endTime-newTime)/1000;//获取天、时、分、秒letdayparseInt(time/(60*60*24));lethouparseInt(time%(60*60*24)/3600);letminparseInt(time%(60*60*24)%3600/60);letsecparseInt(time%(60*60*24)%3600%60);obj{day:this.timeFormat(day),hou:this.timeFormat(hou),min:this.timeFormat(min),sec:this.timeFormat(sec)}}else{//活动已结束,全部设置为'00'obj{day:'00',hou:'00',min:'00',sec:'00'}}countDownArr.push(obj);})//渲染,然后每隔一秒执行一次倒计时函数this.setData({countDownList:countDownArr})setTimeout(this.countDown,1000);},声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

