Chinaunix首页 | 论坛 | 博客
  • 博客访问: 928030
  • 博文数量: 210
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2070
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-19 21:54
文章分类

全部博文(210)

文章存档

2020年(2)

2019年(18)

2018年(27)

2017年(5)

2016年(53)

2015年(88)

2014年(17)

分类: 其他平台

2018-06-07 13:53:51

知识点:获取当前的时间戳,转换成从1970年1月1月0:00:00 距离现在的时间的毫秒数;
Data.parse(new Date())/1000; //得到是毫秒数
WXML:

点击(此处)折叠或打开

  1. <view class="countDownTimeView countDownAllView" >
  2.     <view class="voteText countDownTimeText">{{countDownDay}}天</view>
  3.     <view class="voteText countDownTimeText">{{countDownHour}}时</view>
  4.     <view class="voteText countDownTimeText">{{countDownMinute}}分</view>
  5.     <view class="voteText countDownTimeText">{{countDownSecond}}秒</view>
  6. </view>
JS:

点击(此处)折叠或打开

  1. // pages/vote/vote.js
  2. Page({

  3.   /**
  4.    * 页面的初始数据
  5.    */
  6.   data: {
  7.     current:null,
  8.     current1: null,
  9.     num :1,
  10.     countDownDay:0,
  11.     countDownHour:0,
  12.     countDownMinute: 0,
  13.     countDownSecond: 0,
  14.     weilai: 2515654856,
  15.   },

  16.   /**
  17.    * 生命周期函数--监听页面加载
  18.    */
  19.   onLoad: function (options) {
  20.   
  21.   },

  22.   /**
  23.    * 生命周期函数--监听页面初次渲染完成
  24.    */
  25.   onReady: function () {
  26.     var that = this
  27.     var nowTime = Date.parse(new Date()) / 1000;
  28.     var timeCha = that.data.weilai - nowTime
  29.     console.log("现在时间秒数" + nowTime)
  30.     console.log("未来的时间秒数" + that.data.weilai)
  31.     console.log("相差的时间秒数" + timeCha)
  32.     //timeCha进行提取 天 时 分 秒
  33.     //进行一个持续的时间监听
  34.     var interval = setInterval(function () {
  35.       //秒数计算
  36.       var second = timeCha;
  37.       //天数
  38.       var day = Math.floor(second / 3600 / 24)
  39.       // console.log("天数" + day)
  40.       var dayStr = day.toString();
  41.       if (dayStr.length == 1) {
  42.         dayStr = "0" + dayStr;
  43.       }
  44.       //小时数
  45.       var hr = Math.floor((second - day * 3600 * 24) / 3600)
  46.       // console.log("小时数" +hr)
  47.       var hrStr = hr.toString();
  48.       if (hrStr.length == 1) {
  49.         hrStr = "0" + hrStr;
  50.       }
  51.       // 分钟位
  52.       var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
  53.       // console.log("分钟数" + min)
  54.       var minStr = min.toString();
  55.       if (minStr.length == 1) {
  56.         minStr = '0' + minStr;
  57.       }


  58.       // 秒位
  59.       var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
  60.       // console.log("秒数" + sec)
  61.       var secStr = sec.toString();
  62.       if (secStr.length == 1) {
  63.         secStr = '0' + secStr;
  64.       }
  65.       that.setData({
  66.         countDownDay: day,
  67.         countDownHour: hr,
  68.         countDownMinute: min,
  69.         countDownSecond: sec
  70.       })

  71.       timeCha--;
  72.     //如果时间小于零代表活动结束
  73.       if (second < 0) {
  74.         clearInterval(interval);
  75.         wx.showToast({
  76.           title: '活动已经结束',
  77.         })
  78.         that.setData({
  79.           countDownDay: 0,
  80.           countDownHour: 0,
  81.           countDownMinute: 0,
  82.           countDownSecond: 0
  83.         })
  84.       }

  85.     }.bind(this), 1000)
  86.   },

  87.   /**
  88.    * 生命周期函数--监听页面显示
  89.    */
  90.   onShow: function () {
  91.   
  92.   },

  93.   /**
  94.    * 生命周期函数--监听页面隐藏
  95.    */
  96.   onHide: function () {
  97.   
  98.   },

  99.   /**
  100.    * 生命周期函数--监听页面卸载
  101.    */
  102.   onUnload: function () {
  103.   
  104.   },

  105.   /**
  106.    * 页面相关事件处理函数--监听用户下拉动作
  107.    */
  108.   onPullDownRefresh: function () {
  109.   
  110.   },

  111.   /**
  112.    * 页面上拉触底事件的处理函数
  113.    */
  114.   onReachBottom: function () {
  115.   
  116.   },

  117.   /**
  118.    * 用户点击右上角分享
  119.    */
  120.   onShareAppMessage: function () {
  121.   
  122.   },
  123.   choose:function(e){
  124.     var that =this;
  125.     // console.log(e.currentTarget.dataset.id)
  126.     that.setData({
  127.       current: e.currentTarget.dataset.id
  128.     })
  129.   },
  130.   choose1: function (e) {
  131.     var that = this;
  132.     // console.log(e.currentTarget.dataset.id)
  133.     that.setData({
  134.       current1: e.currentTarget.dataset.id
  135.     })
  136.   },
  137.   choosevote: function (e) {
  138.     var that = this;
  139.     var id = e.currentTarget.dataset.id;
  140.     // console.log(id)
  141.     that.setData({
  142.       current: id
  143.     })
  144.   }
  145. })



阅读(1508) | 评论(0) | 转发(0) |
0

上一篇:tab动画效果

下一篇:提交表单的实际操作

给主人留下些什么吧!~~