今天有位QQ好友问WordPress博客底部的“本站已安全运行XXXX天XXXX小时”是怎么弄的,那么我们将WordPress底部显示网站建立运行时间的几种方法整理出来。
第一种:
<a>感谢您的支持与信任!本博客已正常经运行</a><a id="days"></a>0<a>天</a>
<script>
var s1 = '2013-07-01';//设置为你的建站时间
s1 = new Date(s1.replace(/-/g, "/"));
s2 = new Date();
var days = s2.getTime() - s1.getTime();
var number_of_days = parseInt(days / (1000 * 60 * 60 * 24));
document.getElementById('days').innerHTML = number_of_days;
</script>
第二种:
本博客已安全运行了:<span class="smalltxt"><script>// <![CDATA[
BirthDay=new Date("07 01,2013");//设置为你的建站时间
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
document.write("<font color=red>"+daysold+"</font>天 !");
// ]]></script></span>
第三种:
<span id="runtime_span"></span><script type="text/javascript">function show_runtime(){window.setTimeout("show_runtime()",1000);X=new Date("11/11/2017 1:21:40");Y=new Date();T=(Y.getTime()-X.getTime());M=24*60*60*1000;a=T/M;A=Math.floor(a);b=(a-A)*24;B=Math.floor(b);c=(b-B)*60;C=Math.floor((b-B)*60);D=Math.floor((c-C)*60);runtime_span.innerHTML="网站已运行"+A+"天"+B+"小时"+C+"分"+D+"秒"}show_runtime();</script>
将以上3种代码其中一种添加到当前主题footer.php文件中或者主题页脚小工具