WordPress主题底部显示安全运行时间
如果是RiPro主题,请在diy-footer.php添加。其他主题在对应的footer 文件添加。
方法一:
<script language=”javascript”>
function tick() {
var years,days,hours, minutes, seconds;
var openday = new Date(‘2008/01/01 00:00’); //这里填写建站时间
var today = new Date(); //获取系统当前时间
var total = (today.getTime()-openday.getTime())/1000;
years=Math.floor(total/31536000);
total=total-years*31536000;
days=Math.floor(total/86400);
total=total-days*86400;
hours=Math.floor(total/3600);
total=total-hours*3600;
minutes=Math.floor(total/60);
total=total-minutes*60;
seconds=Math.floor(total);
timeString = “网站运行:”+years+”年”+days+”天”+hours+”时”+minutes+”分”+seconds+”秒”;
document.getElementById(“Clock”).innerHTML = timeString;
window.setTimeout(“tick();”, 1000);
}
window.onload = tick;
</script>
<span id=”Clock”></span>
<!–以上为计时功能代码–>
网站已安全运行:<span id=”run_time” style=”color: black;”></span>
<script>
function runTime() {
var d = new Date(), str = ”;
BirthDay = new Date(“2018-12-31”);
today = new Date();
timeold = (today.getTime() – BirthDay.getTime());
sectimeold = timeold / 1000
secondsold = Math.floor(sectimeold);
msPerDay = 24 * 60 * 60 * 1000
msPerYear = 365 * 24 * 60 * 60 * 1000
e_daysold = timeold / msPerDay
e_yearsold = timeold / msPerYear
daysold = Math.floor(e_daysold);
yearsold = Math.floor(e_yearsold);
//str = yearsold + “年”;
str += daysold + “天”;
str += d.getHours() + ‘时’;
str += d.getMinutes() + ‘分’;
str += d.getSeconds() + ‘秒’;
return str;
}
setInterval(function () {
$(‘#run_time’).html(runTime())
}, 1000);
</script>