This article describes the method of dynamically loading the current time by JS. Share it for your reference. The specific implementation method is as follows:
<body bgcolor="#fef4d9" onload ="time()"> <script language="JavaScript">function time () { var now = new Date(); var yr = now.getYear(); var mName = now.getMonth() + 1; var dName = now.getDay() + 1; var dayNr = ((now.getDate()<10) ? "0" : "")+ now.getDate(); var ampm = (now.getHours() >= 12) ? " PM" : " AM" var hours = now.getHours(); hours = ((hours > 12) ? hours - 12 : hours); var minutes = ((now.getMinutes() < 10) ? ":0" : ":") + now.getMinutes(); var seconds = ((now.getSeconds() < 10) ? ":0" : ":") + now.getSeconds(); if(dName==1) Day = "Sunday"; if(dName==2) Day = "Monday"; if(dName==3) Day = "Tuesday"; if(dName==4) Day = "Wednesday"; if(dName==5) Day = "Thursday"; if(dName==6) Day = "Friday"; if(dName==7) Day = "Saturday"; if(mName==1) Month="January"; if(mName==2) Month="February"; if(mName==3) Month="March"; if(mName==4) Month="April"; if(mName==5) Month="May"; if(mName==6) Month="June"; if(mName==7) Month="July"; if(mName==8) Month="August"; if(mName==9) Month="September"; if(mName==10) Month="October"; if(mName==11) Month="November"; if(mName==12) Month="December"; var DayDateTime=(yr+ "Year"+" "+ Month+ dayNr+ "Day"+ Day+ " + hours+ minutes+ seconds+ " "+ ammp ); document.getElementById ("face").innerText=DayDateTime ; timerID = setTimeout("time()",1000); }</script><form id ="form"> <div> <asp:Label ID ="face" runat ="server" ></asp:Label> </div></form></body>I hope this article will be helpful to everyone's JavaScript programming.