The time code that JavaScript can change in real time:
In many sites have such a function, can display the current event, this may be able to increase the aesthetics, of course, can improve the user-friendliness of the page, can give users real-time understanding of the current time, this can add a lot to the site. Here's a piece of code that can get the current time and be able to format it:
<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><Metaname= "Author"content= "http://www.softwhy.com/" /><title>JavaScript implementation time display code-ant tribe</title><Scripttype= "Text/javascript"> functionClockon (bgclock) {var Now= NewDate (); var Year=now.getyear (); varMonth=Now.getmonth (); varDate=now.getdate (); var Day=Now.getday (); varHour=now.gethours (); varMinu=now.getminutes (); varsec=now.getseconds (); varWeek; Month=Month+1; if(Month<Ten) Month="0"+month; if(Date<Ten) Date="0"+date; if(Hour<Ten) Hour="0"+hour; if(Minu<Ten) Minu="0"+Minu; if(sec<Ten) SEC="0"+sec; varArr_week= NewArray ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); Week=Arr_week[day]; var Time= ""; time= Year+"years"+Month+"Month"+Date+"Day"+Week+""+Hour+":"+Minu+":"+sec; Bgclock.innerhtml="["+ Time+"]"; varTimer=SetTimeout ("Clockon (Bgclock)", $); }window.onload=function(){ varBgclock=document.getElementById ("Bgclock"); Clockon (Bgclock);}</Script></Head><Body><DivID= "Bgclock"></Div></Body></Body></HTML>
The above code to achieve the real-time walking around the effect of the moment, we can directly refer to, the following simple introduction is the method:
This function data has a parameter, which is the element object to accommodate the event.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=7947
For more information, refer to: http://www.softwhy.com/javascript/
A time code that JavaScript can change in real time