A time code that JavaScript can change in real time

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.