跳到导航
跳到搜索
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
try { eventTimers; } catch (e) { eventTimers = document.getElementsByClassName("eventTimer"); function eventTimerRun() { let nowBJ = new Date(new Date() - (8 + new Date().getTimezoneOffset() / 60) * 60 * 60 * 1000); for (let i = 0; i < eventTimers.length; i++) { let start = eventTimers[i].dataset.start.replace("%", ""); start = parseInt(start).toString() === start ? new Date(parseInt(start)) : new Date(start); let end = eventTimers[i].dataset.end.replace("%", ""); end = parseInt(end).toString() === end ? new Date(parseInt(end)) : new Date(end); let info = eventTimers[i].dataset.info; let str = "距离" + info; let timeD = ""; if (start > nowBJ) { timeD = start - nowBJ; str += "开始还有"; } else if (end < nowBJ) { timeD = nowBJ - end; str += "结束已经过去"; } else { timeD = end - nowBJ; str += "结束还有"; } let format = dhms(timeD); if (format[0] > 0) { str += "<b>" + format[0] + "</b>天"; } if (format[1] > 0) { str += "<b>" + format[1] + "</b>时"; } if (format[2] > 0) { str += "<b>" + format[2] + "</b>分"; } // str+=format[3]+"秒" eventTimers[i].innerHTML = str; } } function dhms(timeD) { let day = Math.floor(timeD / 1000 / 60 / 60 / 24); timeD -= day * 1000 * 60 * 60 * 24; let hour = Math.floor(timeD / 1000 / 60 / 60); timeD -= hour * 1000 * 60 * 60; let minute = Math.floor(timeD / 1000 / 60); timeD -= minute * 1000 * 60; let second = Math.floor(timeD / 1000); return [day, hour, minute, second]; } setInterval(eventTimerRun, 1000); }