Displays the time in the Web page in real-time, not only can give the Web page Tim, but also can facilitate the viewer to grasp the current time, in order to improve the speed of web site development, can be encapsulated in a separate function of the main code, in need of direct call and I for the demonstration, directly written in the main page, to facilitate everyone to watch
Recently, there is a Web page to output the current time, accurate to time and minutes, but also timely changes. Baidu looked for, did not find suitable, so they wrote a, collection, easy to use later.
JS timely output The current time
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
function curenttime (divid) {var curtime=new Array (); var now=new Date (); var week=[' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ']; var year=now.getfullyear (); Year var month=now.getmonth () +1; Month var day=now.getdate (); Day var hh=now.gethours (); When Var mm=now.getminutes (); Divided into Var sc=now.getseconds (); Second Var wk=now.getday (); Zhou curtime[' year ']=year; curtime[' Month ']=month<10? 0 ' +month:month; curtime[' Day ']=day<10? ' 0 ' +day:day; curtime[' hh ']=hh<10? ' 0 ' +hh:hh; curtime[' mm ']=mm<10? ' 0 ' +mm:mm; Curtime[' SC ']=sc<10? ' 0 ' +sc:sc; curtime[' wk ']= ' week ' +week[wk]; curtime=curtime[' year ']+ ' +curtime[' month ']+ ' month ' +curtime[' Day ']+ ' th ' + ' ' +curtime[' wk ']+ ' ' +curtime[' ' hh ']+ ': ' + curtime[' mm ']+ ': ' +curtime[' SC ']; document.getElementById (divid). Innerhtml= ' Today is: ' +curtime; SetTimeout (' Curenttime (' +divid+ ') ', 1000); } |
How to use:
Suppose a div with an ID named time exists on the page:
?
| 1 |
<script language= "javascript" >curenttime (' time ');</script> |
The above mentioned is the entire content of this article, I hope you can enjoy.