zoukankan      html  css  js  c++  java
  • 商品秒杀实现和日期与时间戳之间的转换

    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()
    
    
  • 相关阅读:
    C语言中可变函数参数变量的实现
    Oracle电话面试
    JS和C#方法相互调用
    asp.net 页面从初始化到卸载事件顺序
    解决.NET CF 3.5 Bitmap(Stream)未处理异常问题
    sql2008新增时间类数据类型学习
    c#和Javascript操作同一json对象
    被研究生了
    分形
    跑钱
  • 原文地址:https://www.cnblogs.com/shuihanxiao/p/11635315.html
Copyright © 2011-2022 走看看