Home >Web Front-end >JS Tutorial >js real-time acquisition of system current time instance code_javascript skills

js real-time acquisition of system current time instance code_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:30:591311browse

(1): First, use JS to write the function clockon() that displays the system time in real time. It has only one parameter bgclock, which is used to specify the name of the converted

tag. There is no return value. Everyone is developing the website. You can save the modified function in a JS file for reuse. The code is as follows:

Copy the code The code is as follows:

<script><br>function clockon(bgclock)<br>{<br> var now = new Date();<br> var year = now.getYear();<br> var month = now .getMonth();<br> var date = now.getDate();<br> var day = now.getDay();<br> var hour = now.getHours();<br> var minu = now.getMinutes ();<br> var sec = now.getSeconds();<br> var week;<br> month = month 1;<br> if(month<10)month="0" month;<BR> if( date<10)date="0" date;<BR> if(hour<10)hour="0" hour;<BR> if(minu<10)minu="0" minu;<BR> if(sec< 10)sec="0" sec;<BR> var arr_week = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");<BR> week = arr_week[day];<BR> var time = "";<BR> time = year "year" month "month" date "day" week "" hour ";" minu ";" sec;<BR> if(document.all)<BR> {<BR> bgclock.innerHTML="[" time "]"<BR> }<BR> var timer = setTimeout("clockon(bgclock)",200); <BR>} <BR></script>

(2): Call in the onload event of the page's and place the div tag where it is to be displayed. Code:

Copy code The code is as follows:


< ;/div>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn