AI摘要:提供三种HTML代码,用于在网站底部显示网站运行时间,包括天数、小时、分钟和秒。
演示

代码如下[提供三种]
代码一
♾️ html 代码: <center>
今天是:<span><script language=Javascript type=text/Javascript>
var day="";
var month="";
var ampm="";
var ampmhour="";
var myweekday="";
var year="";
mydate=new Date();
myweekday=mydate.getDay();
mymonth=mydate.getMonth()+1;
myday= mydate.getDate();
myyear= mydate.getYear();
year=(myyear > 200) ? myyear : 1900 + myyear;
if(myweekday == 0)
weekday=" 星期日 ";
else if(myweekday == 1)
weekday=" 星期一 ";
else if(myweekday == 2)
weekday=" 星期二 ";
else if(myweekday == 3)
weekday=" 星期三 ";
else if(myweekday == 4)
weekday=" 星期四 ";
else if(myweekday == 5)
weekday=" 星期五 ";
else if(myweekday == 6)
weekday=" 星期六 ";
document.write(year+"年"+mymonth+"月"+myday+"日 "+weekday);
</script>
</div>
<center><b><FONT COLOR="#008B00">【本站已经可爱滴运行】</FONT></b>
<span id="span_dt_dt"></span>
<SCRIPT language=javascript>
<!--
//document.write("");
function show_date_time(){
window.setTimeout("show_date_time()", 1000);
BirthDay=new Date("3-9-2020 08: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=(daysold-e_daysold)*-24;
hrsold=Math.floor(e_hrsold);
e_minsold=(hrsold-e_hrsold)*-60;
minsold=Math.floor((hrsold-e_hrsold)*-60);
seconds=Math.floor((minsold-e_minsold)*-60);
span_dt_dt.innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒" ;
}
show_date_time();
//-->
</SCRIPT>
</center>
</span>
代码二
♾️ html 代码: <span id="website_runtime"></span>
<script type="text/javascript">
function show_runtime(){
// 定时器
window.setTimeout("show_runtime()", 1000);
// 开始时间
let start = new Date("2019/02/08 00:00:00");
// 当前时间
let now = new Date();
// 经过时长
let duration = now.getTime() - start.getTime();
// 一天的毫秒数
let msPerDay = 24 * 60 * 60 * 1000;
// 天
let _day = duration / msPerDay;
let day = Math.floor(_day);
// 小时
let _hour = (_day - day) * 24;
let hour = Math.floor(_hour);
// 分钟
let _minute = (_hour - hour) * 60;
let minute = Math.floor(_minute);
// 秒
let _second = (_minute - minute) * 60;
let second = Math.floor(_second);
// 更新span标签内容
website_runtime.innerHTML="本站已运行:" + day + "天" + hour + "小时" + minute + "分" + second + "秒";
}
show_runtime();
</script>
代码三
♾️ html 代码: <span id="website_runtime"></span>
<script type="text/javascript">
function show_runtime(){window.setTimeout("show_runtime()",1000);x=new Date("2019/02/08 00:00:00");y=new Date();z=y.getTime()-x.getTime();mspd=24*60*60*1000;_d=z/mspd;d=Math.floor(_d);_h=(_d-d)*24;h=Math.floor(_h);_m=(_h-h)*60;m=Math.floor(_m);_s=(_m-m)*60;s=Math.floor(_s);website_runtime.innerHTML="本站已运行:"+d+"天"+h+"小时"+m+"分"+s+"秒";}show_runtime();
</script>
然后加在你网站的底部代码中,改一下代码中的时间信息即可