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
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:
The above mentioned is the entire content of this article, I hope you can enjoy.