<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>本网站已建立</title> </head> <body> <h1 id="time"></h1> </body> </html> <script>
function auto() {
var a = new Date();//获取现在的时间
var d = Date.parse("2020-05-20T00:00:00");//设定网站建立的时间
var t = a.getTime()-d;//计算网站已经建立了多少时间
//计算并输出网站建立的时间
//通过取余运算符和取整方法计算
var n=parseInt(t/31536000000);
var m=t%31536000000;
var y=parseInt(m/2592000000);;
var m=t%2592000000;
var r=parseInt(m/86400000);
var m=t%86400000;
var xs=parseInt(m/3600000);;
var m=t%3600000;
var fz=parseInt(m/60000);
var m=t%60000;
var miao=parseInt(m/1000);
document.getElementById("time").innerHTML="本网站已建立:"+n+"年"+y+"月"+r+"日"+xs+"时"+fz+"分"+miao+"秒"
}
setInterval(auto,1000)
</script>