处理预售时间

processingTime(val) {

let nowTime = this.data.timestamp && new Date(this.data.timestamp);   

// 当前时间戳timestamp: '',通过服务端接口获得,new Date().getTime()会有误差

let beginTime = val && new Date(val.replace(/-/g, "/"));

if (nowTime instanceof Date && beginTime instanceof Date) {

let nowDay = this.getDayTime(nowTime);

let beginDay = this.getDayTime(beginTime);

let timeDiff = (beginDay - nowDay) / 1000 / 60 / 60 / 24;

let str = "";

if (timeDiff >= 2) {

this.data.yd_flag = false;

} else if (timeDiff >= 1) {

str = "明日";

} else if (timeDiff < 1) {

str = "今日";

}

this.setData({

timeStr: `${str}${beginTime.getHours()}:${beginTime.getMinutes() ||

"00"}送达`

})

}

},

getDayTime(time) {

if (time instanceof Date) {

return new Date(time.getFullYear(), time.getMonth(), time.getDate());

}

},

你可能感兴趣的:(处理预售时间)