在页面中添加动态时间
在页面中添加动态时间
第一次写文章,想写一篇稍微简单的文章,想了又想还是写写最近在网页中添加的动态时间功能(初学者,大神勿喷)
{script}
var dtime=new Date();
var year = dtime.getFullYear();
var month = dtime.getMonth()+1;
var day = dtime.getDay();
var hours=dtime.getHours();
var minutes=dtime.getMinutes();
var seconds=dtime.getSeconds();
var dn="AM";
if (hours>12){
dn="PM";
hours=hours-12
}
if (hours==0)
hours=12;
if (minutes<=9)
minutes="0"+minutes;
if (seconds<=9)
seconds="0"+seconds;
var ctime=year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds+" "+dn;
document.getElementById("timeNow").innerHTML="<b style='align-content: center'>"+ctime+"</b>";
setTimeout("show2()",1000)
}
window.onload=show2`
{html}
<h1 id="tick2">
时间
</h1>
这样就能实现时间动态展示