全部文章-技术教程

页脚添加网站稳定运行时长的代码

admin · 6月29日 · 2019年 · · 3109次已读

别人网站底部显示的网站运行时间是什么设置的?是插件的效果吗?
不用插件,一段JS代码就可以实现同样的效果。

效果展示

页脚添加网站稳定运行时长的代码

使用方法

复制下面代码,放到当前主题的页脚文件footer.php即可

样式1

站点已稳定运行:<SPAN id=span_dt_dt style="color: #2F889A;"></SPAN> <SCRIPT language=javascript>function show_date_time(){
    window.setTimeout("show_date_time()", 1000);
    BirthDay=new Date("07/23/2018 00:00:00");
    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);
    e_hrsold=(e_daysold-daysold)*24;
    hrsold=Math.floor(e_hrsold);
    e_minsold=(e_hrsold-hrsold)*60;
    minsold=Math.floor((e_hrsold-hrsold)*60);
    seconds=Math.floor((e_minsold-minsold)*60);
    span_dt_dt.innerHTML='<font style=color:#C40000>'+daysold+'</font> 天 <font style=color:#C40000>'+hrsold+'</font> 时 <font style=color:#C40000>'+minsold+'</font> 分 <font style=color:#C40000>'+seconds+'</font> 秒';
    }
    show_date_time();</script>

样式2

网站已运行:<span id="run_time" style="color: black;"></span>
<script>
function runTime() {
    var d = new Date(), str = '';
    BirthDay = new Date("2018-07-23");
    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>

样式3

<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span><script>// <![CDATA[
var now = new Date(); 
function createtime(){ var grt= new Date("07/23/2018 00:00:00");//此处修改你的建站时间或者网站上线时间 
now.setTime(now.getTime()+250); 
days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days); 
hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours); 
if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum); 
mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;} 
seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum); 
snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;} 
document.getElementById("timeDate").innerHTML = "本站已安全运行"+dnum+"天"; 
document.getElementById("times").innerHTML = hnum + "小时" + mnum + "分" + snum + "秒"; } 
setInterval("createtime()",250);
// ]]></script>

样式4

本博客已安全运行了:<span class="smalltxt"><script>// <![CDATA[
BirthDay=new Date("07 23,2018");//设置为你的建站时间
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>

样式5

<a>感谢您的支持与信任!本博客已正常经运行<a id="days">0</a>天</a>
<script>
var s1 = '2018-07-23';//设置为你的建站时间
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>

样式6

<SCRIPT language=javascript>
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("07/23/2018 00:00:00");//这个日期是可以修改的
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);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
span_dt_dt.innerHTML=""+daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";
}
show_date_time();
</SCRIPT>

0 条回应
站点已稳定运行:
你的IP:
耗时 0.243 秒 | 查询 63 次 | 内存 7.32 MB