添加网站运行时间

2019/08/13
共 343 字
约 1 分钟
归档: 技术
标签: Hexo

本站已经勉强运行14天


参考教程

添加网站运行时间

操作过程

  1. 在footer.ejs最后添加

<div id="foot">
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
    var now = new Date(); 
    function createtime() { 
        var grt= new Date("07/29/2019 12: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>
</div>
  1. 响应式的处理:在footer.styl添加


@media (max-width:400px) {
	#foot {
	    font-size: 5px;
	    color: #999999;
	    font-family: Menlo, Monaco, "Andale Mono", "lucida console", "Courier New", monospace;
	    text-shadow: 0 1px #fff;
	    padding-top: 30px;
	    margin: 10px 40px 3px 40px;
	    text-align: center;
	}
}

#foot {
    font-size: 12px;
    font-family: Menlo, Monaco, "Andale Mono", "lucida console", "Courier New", monospace;
    text-shadow: 0 1px #fff;
    margin: -15px 40px 10px 40px;
    padding-bottom: 5px;
    text-align: center;
}

大功告成

计算时间的函数应该可以再优化的,以后再处理。

留言

本站已运行
© 2024 Jack  由 Hexo 驱动
复制成功