大家现在看到很多人的博客上都添加了这一功能,显示网站从建立到现在已经运行的时间。有些人在应用中心也找到了网站运行时间这个插件,但是对于用emlog 5.1的人可能会发现,这个插件本身跟emlog 5.1稍微有一点冲突,所以对于很多人来说很是烦恼。那么怎样才能在页面中实现这一功能呢?今天就来教大家:
首先,大家可以看到本站的底部的右下角显示了本站运行时间,今天就按照本站的功能实现方法来讲解,其实实现起来很简单,只需要在想显示时间的地方插入一段代码即可。代码如下:
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span> <script language="javascript">
var now = new Date();
function createtime(){
var grt= new Date("07/03/2013 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>
THE END