这个例子分享了微信小程序动态显示项目倒计时的具体代码,供大家参考。具体内容如下
1.显示效果如下
2.wxml代码:
!-倒计时-文本wx: if=' {{clock!=''}} '只有{ { clock } }/text text wx : if=' { { clock==' ' } } '已过期/text3,js代码:
在小组项目中获得的活动结束时间的格式如下
格式转换newdate(即。数据。崩溃。collapse _ end)。因为格式无法正常计算持续时间,所以执行了gettime()
//倒计时功能倒计时(即){var end time=new date(即。data.collapse.collapse _ end)。gettime()| |[];//console . log(end time);var NowTime=新日期()。getTime();var total _ micro _ second=end time-now time | |[];//单位毫秒if(total _ micro _ second 0){//console . log('时间初始化小于0,活动已结束');total _ micro _ second=1;//单位毫秒——为什么?} //console.log('剩余时间:' total _ micro _ second ');//渲染倒计时时钟that . setdata({ clock : date format(total _ micro _ second)//如果完成,这里输出‘0天0小时0分0秒’);如果(total _ micro _ second=0){那。setdata ({clock: '已过期' });返回;} setTimeout(function(){ total _ micro _ second-=1000;倒计时;},1000)} //以时间打印格式为例,函数dateformat (micro _ second)将在11天03小时25分19秒内每1s调用一次{//total seconds varsecond=math。地板(微秒/1000);//day varday=数学。楼层(二楼/3600/24);//小时var HR=数学。楼层(二层/3600% 24层);//min var min=Math.floor(秒/60% 60);//秒var sec=Math.floor(秒% 60);返回日'天'小时'小时'分钟'秒'秒;} page ({onload :函数(options){ wx . request({ success :函数(request){//倒计时(获取结束时间后调用倒计时方法)倒计时(即);}})})以上就是本文的全部内容。希望对大家的学习有帮助,支持我们。