知识点:获取当前的时间戳,转换成从1970年1月1月0:00:00 距离现在的时间的毫秒数;
Data.parse(new Date())/1000; //得到是毫秒数
WXML:
-
<view class="countDownTimeView countDownAllView" >
-
<view class="voteText countDownTimeText">{{countDownDay}}天</view>
-
<view class="voteText countDownTimeText">{{countDownHour}}时</view>
-
<view class="voteText countDownTimeText">{{countDownMinute}}分</view>
-
<view class="voteText countDownTimeText">{{countDownSecond}}秒</view>
-
</view>
JS:
-
// pages/vote/vote.js
-
Page({
-
-
/**
-
* 页面的初始数据
-
*/
-
data: {
-
current:null,
-
current1: null,
-
num :1,
-
countDownDay:0,
-
countDownHour:0,
-
countDownMinute: 0,
-
countDownSecond: 0,
-
weilai: 2515654856,
-
},
-
-
/**
-
* 生命周期函数--监听页面加载
-
*/
-
onLoad: function (options) {
-
-
},
-
-
/**
-
* 生命周期函数--监听页面初次渲染完成
-
*/
-
onReady: function () {
-
var that = this
-
var nowTime = Date.parse(new Date()) / 1000;
-
var timeCha = that.data.weilai - nowTime
-
console.log("现在时间秒数" + nowTime)
-
console.log("未来的时间秒数" + that.data.weilai)
-
console.log("相差的时间秒数" + timeCha)
-
//timeCha进行提取 天 时 分 秒
-
//进行一个持续的时间监听
-
var interval = setInterval(function () {
-
//秒数计算
-
var second = timeCha;
-
//天数
-
var day = Math.floor(second / 3600 / 24)
-
// console.log("天数" + day)
-
var dayStr = day.toString();
-
if (dayStr.length == 1) {
-
dayStr = "0" + dayStr;
-
}
-
//小时数
-
var hr = Math.floor((second - day * 3600 * 24) / 3600)
-
// console.log("小时数" +hr)
-
var hrStr = hr.toString();
-
if (hrStr.length == 1) {
-
hrStr = "0" + hrStr;
-
}
-
// 分钟位
-
var min = Math.floor((second - day * 3600 * 24 - hr * 3600) / 60);
-
// console.log("分钟数" + min)
-
var minStr = min.toString();
-
if (minStr.length == 1) {
-
minStr = '0' + minStr;
-
}
-
-
-
// 秒位
-
var sec = second - day * 3600 * 24 - hr * 3600 - min * 60;
-
// console.log("秒数" + sec)
-
var secStr = sec.toString();
-
if (secStr.length == 1) {
-
secStr = '0' + secStr;
-
}
-
that.setData({
-
countDownDay: day,
-
countDownHour: hr,
-
countDownMinute: min,
-
countDownSecond: sec
-
})
-
-
timeCha--;
-
//如果时间小于零代表活动结束
-
if (second < 0) {
-
clearInterval(interval);
-
wx.showToast({
-
title: '活动已经结束',
-
})
-
that.setData({
-
countDownDay: 0,
-
countDownHour: 0,
-
countDownMinute: 0,
-
countDownSecond: 0
-
})
-
}
-
-
}.bind(this), 1000)
-
},
-
-
/**
-
* 生命周期函数--监听页面显示
-
*/
-
onShow: function () {
-
-
},
-
-
/**
-
* 生命周期函数--监听页面隐藏
-
*/
-
onHide: function () {
-
-
},
-
-
/**
-
* 生命周期函数--监听页面卸载
-
*/
-
onUnload: function () {
-
-
},
-
-
/**
-
* 页面相关事件处理函数--监听用户下拉动作
-
*/
-
onPullDownRefresh: function () {
-
-
},
-
-
/**
-
* 页面上拉触底事件的处理函数
-
*/
-
onReachBottom: function () {
-
-
},
-
-
/**
-
* 用户点击右上角分享
-
*/
-
onShareAppMessage: function () {
-
-
},
-
choose:function(e){
-
var that =this;
-
// console.log(e.currentTarget.dataset.id)
-
that.setData({
-
current: e.currentTarget.dataset.id
-
})
-
},
-
choose1: function (e) {
-
var that = this;
-
// console.log(e.currentTarget.dataset.id)
-
that.setData({
-
current1: e.currentTarget.dataset.id
-
})
-
},
-
choosevote: function (e) {
-
var that = this;
-
var id = e.currentTarget.dataset.id;
-
// console.log(id)
-
that.setData({
-
current: id
-
})
-
}
-
})
-
<view class="countDownTimeView countDownAllView" >
-
<view class="voteText countDownTimeText">{{countDownDay}}天</view>
-
<view class="voteText countDownTimeText">{{countDownHour}}时</view>
-
<view class="voteText countDownTimeText">{{countDownMinute}}分</view>
-
<view class="voteText countDownTimeText">{{countDownSecond}}秒</view>
-
</view>
-
<view class="countDownTimeView countDownAllView" >
-
<view class="voteText countDownTimeText">{{countDownDay}}天</view>
-
<view class="voteText countDownTimeText">{{countDownHour}}时</view>
-
<view class="voteText countDownTimeText">{{countDownMinute}}分</view>
-
<view class="voteText countDownTimeText">{{countDownSecond}}秒</view>
-
</view>
阅读(1559) | 评论(0) | 转发(0) |