如何显示自上次用户访问网页以来的小时数?我想在Javascript中这样做,但JQuery也很好。
答案 0 :(得分:1)
假设您有getCookie
and setCookie
functions:
const lastVisit = getCookie('lastVisitTime');
const now = Date.now();
if (lastVisit) {
const hoursSinceLastTime = Math.ceil((parseInt(lastVisit) - now) / 3600);
alert(`It's been ${hoursSinceLastTime} hour(s) since you last visited us.`);
}
setCookie('lastVisitTime', now);