小程序时间转时间戳进行比较,安卓和ios的兼容写法

str2Stamp(time){
	var date = time.substr(0, 10)

var hour = time.substr(11, 2) == ‘00’ ? 0 : time.substr(11, 2).replace(/\b(0+)/gi, “”);
var minute = time.substr(14, 2) == ‘00’ ? 0 : time.substr(14, 2).replace(/\b(0+)/gi, “”);
var second = time.substr(17, 2) == ‘00’ ? 0 : time.substr(17, 2).replace(/\b(0+)/gi, “”);
var timestamp = parseInt(new Date(date).getTime() / 1000) + parseInt(hour) * 3600 + parseInt(minute) * 60 + parseInt(second) - 28800
return new Date(timestamp * 1000);
},
onshow(){
// 获取现在的时间然后记录一下
var logs = wx.getStorageSync(‘date’) || []
console.log(“logs” + logs)
this.date = util.formatTime(new Date())
console.log(“this.date” + this.date)
var timestamp = this.str2Stamp(this.date);
console.log(“timestamp” + timestamp)
let time = Math.round((timestamp - logs)/60000).toString();
console.log(“time” + time)
if (time>=-1){
wx.showToast({
title: ‘来了来了…’,
icon: ‘loading’,
duration: 500
})
this.qingkong()
}
wx.setStorageSync(‘date’, timestamp)
}

你可能感兴趣的:(自定义组件)