小程序 小程序倒计时时间戳的控制
// "2017/10/1 00:00"
kaiShi: function (a) {
var that = this;
function nowTime() {
var dateTime = new Date();
var timestamp = Date.parse(new Date());
var serverTime = new Date(a);
var difference = serverTime - dateTime.getTime();
var nMS = difference;
// var myD = Math.floor(nMS / (1000 * 60 * 60 * 24)); //天
var myH = Math.floor(nMS / (1000 * 60 * 60)) % 24; //小时
var myM = Math.floor(nMS / (1000 * 60)) % 60; //分钟
var myS = Math.floor(nMS / 1000) % 60; //秒
if (myH >= 0) {
var str = myH + "小时" + myM + "分" + myS + "秒";
} else {
var str = "已结束!";
clearInterval(timer);
}
// console.log(dateTime);
// console.log(str);
// this.xianZai();
// that.setData({
// countDown: str,
// });
// return str;
// var wearList = that.data.wearList
// wearList[i].date = str;
var wearList = that.data.wearList
for (var i = 0; i < wearList.length; i++) {
wearList[i].date = str;
}
that.setData({
wearList: wearList
})
}
nowTime();
var timer = setInterval(nowTime, 1000);
// return nowTime()
},