This article mainly introduces the use of JS to display the current time sample, here also use jquery, let it also be introduced into the page
The front page display code is as follows: <span id= "Clock" style= "FONT-SIZE:14PX;" ></span> JS script code as follows: $ (document). Ready (function () {//The first showTime ();//The second type of Var clock = new Clock (); Clock.display ($ ("#clock")); }); //Display system current time processing the first method function ShowTime () { var myarray = new Array (7); var TD = new Date (); m Yarray[0] = "Sunday"; &NBSP;MYARRAY[1] = "Monday"; &NBSP;MYARRAY[2] = "Tuesday"; &NBSP;MYARRAY[3] = "Wednesday"; &NBSP;MYARRAY[4] = "Thursday"; &NBSP;MYARRAY[5] = "Friday"; &NBSP;MYARRAY[6] = "Saturday"; weekday = Td.getday (); var h = td.gethours (); var m = td.getminutes (); var s = td.getseconds (); var hstr = h; var MSTR = m; var ISTR = s; if (H <) {Hstr = "0" + H}; if (M <) {MSTR = "0" + m}; if (S <) {ISTR = "0" + s}; $ ("#clock"). InnerHTML (' Current time: ' + new Date (). tolocaledatestring () + "" + Myarray[weekday] + "" + Hstr + ":" + MSTR + ":" + ISTR); settimeout (showTime, 1000); //Display system current time processing the second method function Clock () {var date = new Date (); This.year=date.getfullyear (); This.month=date.getmon th () +1; This.date=date.getdate (); This.day=newarray ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") [Date.getday ()]; This.hour=date.gethours () <10? " 0 "+date.gethours ():d ate.gethours (); This.minute=date.getminutes () <10? " 0 "+date.getminutes ():d ate.getminutes (); This.second=date.getseconds () <10? " 0 "+date.getseconds ():d ate.getseconds (); This.tostring=function () {return "Now time is:" +this.year+ "year" +this.month+ "month" +this.date+ "Day" +this.hour+ ":" + This.minute+ ":" +this.second+ "" +this.day; }; This.tosimpledate=function () {returnthis.year+ "-" +this.month+ "-" +this.date;}; This.todetaildate=function () {returnthis.year+ "-+this.month+"-"+this.date+" "+this.hour+": "+this.minute+" : "+this.second;}; This.display=function (ele) {varclock=newclock (); ele.innerhtml=clock.tostring (); Window.settimeout (function () {clock.display (ele);},1000); }; }