JS前端处理每天弹窗只弹一次
function isNotSameDay() {
try {
let startTime = localStorage.getItem("discoverTime");
if (startTime && startTime !== " ") {
startTime = Number(startTime);
} else {
localStorage.setItem("discoverTime", +new Date());
return Promise.resolve(true);
}
const startTimeMs = new Date(startTime).setHours(0, 0, 0, 0);
const endTimeMs = new Date().setHours(0, 0, 0, 0);
localStorage.setItem("discoverTime", +new Date());
const result = startTimeMs === endTimeMs ? false : true;
console.log("resultresultresult", result);
if (result) {
return Promise.resolve(result);
} else {
return Promise.resolve(result);
}
} catch (err) {
console.log("err", err);
return Promise.resolve(false);
}
},