Javascript 实现动态显示网站已经运行XX天



Javascript 实现动态显示网站已经运行XX天

源码文件可以查看:

<style>
	div {
		background: #4C1F02;
		width: 750px;
		height: 450px;
		line-height: 150px;
		text-align: center;
		color: #fff;
		font-size: 30px;
	}
</style>
<div>
	<!--建站迷(https://jianzhanmi.com)<br>-->
	<span style="font-size: 40px;">本站已运行</span><br>
	<span id="timeDate">载入天数...</span>
	<span id="times">载入时分秒...</span>
</div>
<script>
	var now = new Date();

	function createtime() {
		var grt = new Date("01/02/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>

工作中


没有账号? 忘记密码?

社交账号快速登录