杂物间 || 网站上线运行时间统计
自行修改建站时间即可。
<div id="sitetime" style="text-align: center;"></div>
<script>
function siteTime() {
window.setTimeout("siteTime()", 1000);
var seconds = 1000;
var minutes = seconds * 60;
var hours = minutes * 60;
var days = hours * 24;
var years = days * 365;
var today = new Date();
var todayYear = today.getFullYear();
var todayMonth = today.getMonth() + 1;
var todayDate = today.getDate();
var todayHour = today.getHours();
var todayMinute = today.getMinutes();
var todaySecond = today.getSeconds();
var t1 = Date.UTC(2023, 1, 1, 0, 0, 0); // 北京时间2023-01-01 00:00:00创建网站的时间,修改此处的时间既是建站时间。
var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
var diff = t2 - t1;
var diffYears = Math.floor(diff / years);
var diffDays = Math.floor((diff / days) - diffYears * 365);
var diffHours = Math.floor((diff - (diffYears * 365 + diffDays) * days) / hours);
var diffMinutes = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours) / minutes);
var diffSeconds = Math.floor((diff - (diffYears * 365 + diffDays) * days - diffHours * hours - diffMinutes * minutes) / seconds);
document.getElementById("sitetime").innerHTML = '数据统计:本站已上线运行 ' + diffYears + "年" + diffDays + "天" + diffHours + "小时" + diffMinutes + "分" + diffSeconds + "秒";
}
siteTime();
</script>
没有一键复制的按钮吗
需求收到👌
暂时没有这个按钮哈,因为这个代码量不大,可以选中复制