商品秒杀实现和日期与时间戳之间的转换

1,秒杀点击状态字体增大加粗,颜色加深,秒杀分“抢购中”和“即将开始”两种状态

wxml代码如下

<view bindtap="changeTime" wx:for="{{seckilltime}}" wx:key="index" wx:for-item="titem" data-titem="{{titem}}" data-index="{{index}}" class="{{titem.status=='1'?'scroll-item-act':'scroll-item'}}" >
                    <view class="scroll-item-time">{{titem.showBeinDate}}</view>
                    <view class="line"></view>
                    <view class="scroll-item-st" wx:if="{{titem.timeStart=='3'}}">抢购中</view>
                    <view class="scroll-item-st" wx:if="{{titem.timeStart!='3'}}">即将开始</view>
                </view>

文字的修改需要根据秒杀时间与当前时间的对比来修改,而点击实现不通效果,根据绑定的class,点击使用scroll-item-act

2,js

changeTime:function(e){
  let curItemNun=e.currentTarget.dataset.titem;
  let curIndex=e.currentTartget.dataset.index;
  if(curItemNun.status==1){
    return
  }
 this.data.secilltime.map(item=>{
  item.status=0
 })
 this.data.secilltime[curIndex].status=1;
  this.setData({
    secilltime:this.data.secilltime
  })
}

3,小程序中时间戳转日期

formateDate:funciton("需要转换的时间戳"){
   let date = new Date(times);
   let y = date.getFullYear();
   let MM = date.getMonth() + 1;
   MM = MM < 10 ? ('0' + MM) : MM;
   let d = date.getDate();
   d = d < 10 ? ('0' + d) : d;
   let h = date.getHours();
   h = h < 10 ? ('0' + h) : h;
   let m = date.getMinutes();
   m = m < 10 ? ('0' + m) : m;
   let s = date.getSeconds();
    s = s < 10 ? ('0' + s) : s;
    return y+'/'+MM+'/'+d+" "+h+':'+m+':'+'s';
}

4,小程序中日期格式转时间戳只需要

new Date('需要转换的日期如 2019/10/08 14:30:30').getTime()

原文地址:https://www.cnblogs.com/shuihanxiao/p/11635315.html