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()
    
    
  • 相关阅读:
    递归算法解析成树形结构
    Tomcat性能参数设置
    hibernate.cfg.xml 配置(摘录)
    OpenCms 集成外部Solr Server
    安装配置OPENCMS的Replication cluster(从)详细过程
    ruby 格式化当前日期时间
    Ruby 语法快速入门
    ruby condition
    配置 RAILS FOR JRUBY1.7.4
    我的权限系统设计实现MVC4 + WebAPI + EasyUI + Knockout(五)框架及Web项目的组件化
  • 原文地址:https://www.cnblogs.com/shuihanxiao/p/11635315.html
Copyright © 2011-2022 走看看