diff --git a/packkey/libs.js b/libs.js similarity index 59% rename from packkey/libs.js rename to libs.js index 2e34302..a220f8e 100644 --- a/packkey/libs.js +++ b/libs.js @@ -40,3 +40,31 @@ const getQueryString = (name) => { if (r != null) return unescape(r[2]); return null; }; + +/** 倒计时函数 + * @param {*} timestamp + * @returns + */ +const pageOutTime = (timestamp) => { + if (timestamp) { + const now = new Date().getTime(); // 获取当前时间的时间戳 + let diff = Number(timestamp) - now; // 计算差异(以毫秒为单位) + + // 判断还剩多久 + if (diff <= 0) { + // window.location.replace("/outtime.html"); + console.log("时间已到"); + return false; + } else { + // 将差异转换为小时、分钟、秒 + const hours = Math.floor(diff / (1000 * 60 * 60)); + diff -= hours * (1000 * 60 * 60); + const minutes = Math.floor(diff / (1000 * 60)); + diff -= minutes * (1000 * 60); + const seconds = Math.floor(diff / 1000); + + // 返回结果数组 + return [hours, minutes, seconds]; + } + } +}; diff --git a/outtime.html b/outtime.html new file mode 100644 index 0000000..cd4e600 --- /dev/null +++ b/outtime.html @@ -0,0 +1,52 @@ + + + +
+ + +