找到网站目录 /usr/themes/Cuteen/include/ 在底部合适位置添加第一行 JS 引用代码,之后再添加 JS 即可!
<span id="sitetime"></span> //js 调用 ...
JavaScript
<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(2017,11,11,16,16,16); // 此处是开始时间,北京时间 2017-11-11 16:16:16
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>...
JavaScript
PHP 代码 2
<?php
$launchDate = new DateTime('2023-01-01 00:00:00');
$now = new DateTime();
$diff = $now->diff($launchDate);
// 输出初始时间
echo '<div id="timeDisplay">';
echo '网站已经运行了 ' . $diff->y . ' 年 ' . $diff->m . ' 月 ' . $diff->d . ' 天 ' . $diff->h . ' 小时 ' . $diff->i . ' 分钟 ' . $diff->s . ' 秒。';
echo '</div>';
// 输出 JavaScript 代码
echo '<script>';
echo 'function updateTime() {';
echo ' var now = new Date();';
echo ' var launchDate = new Date("2023-01-01T00:00:00");';
echo ' var diff = Math.floor((now - launchDate) / 1000);';
echo ' var seconds = diff % 60;';
echo ' var minutes = Math.floor(diff / 60) % 60;';
echo ' var hours = Math.floor(diff / 3600) % 24;';
echo ' var days = Math.floor(diff / 86400);';
echo ' document.getElementById("timeDisplay").innerHTML = "网站已经运行了 " + days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 .";';
echo '}';
echo 'setInterval(updateTime, 1000);';
echo '</script>';
?>
PHP