Window.onload =function (){ varODIV1 = document.getElementById ("Div1"); functionGetTime () {varMyDate =NewDate (); varMyyear =mydate.getfullyear (), Mymonth= Mydate.getmonth () + 1, Mynowdate=mydate.getdate (), Myday=mydate.getday (), Myhour=mydate.gethours (), Myminutes=mydate.getminutes (), Myseconds=mydate.getseconds (); Myhour=Newnum (Myhour); Myminutes=Newnum (myminutes); Myseconds=Newnum (myseconds); Myday=Changeday (Myday); Odiv1.innerhtml= Myyear + "Year" + Mymonth + "Month" + mynowdate + "Day" + "Week" + myday + "<br>" +myhour + ":" + myminutes + ":" +Myseconds; } functionNewnum (obj) {if(Obj < 10) {obj= "0" +obj; } returnobj; } functionChangeday (obj) {Switch(obj) { Case1:obj = "One" ; Break; Case2:obj = "Two" ; Break; Case3:obj = "three" ; Break; Case4:obj = "Four" ; Break; Case5:obj = "Five" ; Break; Case6:obj = "Six" ; Break; Case0:obj = "Day" ; Break; } returnobj; } getTime (); varTime = SetInterval (gettime,1000); }
The above is the JS section
The page HTML section is as follows
<!DOCTYPE HTML><HTML> <Head> <title>Current time</title> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <styletype= "Text/css">#div1{font-size:20px;Font-weight:Bold;} </style> </Head> <Body> <DivID= "Div1"Align= "Center"></Div> </Body></HTML>
Show the current time