Topic Analysis:
Use the JavaScript Date object to display the current date and time, first define a time Odate object with the new date (), and then get the value of the month, day, and hour by the Odate object:
var odate=new Date ();
var oyear=odate.getfullyear (); Get year of year
var omonth=odate.getmonth () +1; Gets the month of the month
var oday=odate.getdate (); Gets the date of the day
var ohours=odate.gethours (); Get the hour of the day
var ominute=odate.getminutes (); Get how many points at that time
var oseconds=odate.getseconds (); Get how many seconds
To connect the acquired good days and hours to the time and seconds.
var timevalue=oyear+ "-" +zero (omonth) + "-" +zero (oday) + "" +zero (ohours) + ":" +zero (Ominute) + ":" +zero (oseconds) paid Div
Obox.innerhtml=timevalue;
The zero () function inside is a 0 function, with a value less than 10 for the day of the month, plus 0 in front.
function zero (num) {
return Num>10?num: "0" +num;
}
Then run the clock () by using the SetInterval () method. It's just, every 1 seconds.
SetInterval ("clock ()", 1000);
JavaScript code:
Window.onload=function () {
Clock ();
SetInterval ("clock ()", 1000);
}
function zero (num) {
return Num>10?num: "0" +num;
}
function Clock () {
var Obox=document.getelementbyid ("date");
var odate=new Date ();
var oyear=odate.getfullyear ();
var omonth=odate.getmonth () +1;
var oday=odate.getdate ();
var ohours=odate.gethours ();
var ominute=odate.getminutes ();
var oseconds=odate.getseconds ();
var timevalue=oyear+ "-" +zero (omonth) + "-" +zero (oday) + "" +zero (ohours) + ":" +zero (Ominute) + ":" +zero (Oseconds);
Obox.innerhtml=timevalue;
}
Reprint front-end rookie: http://www.bird100.cn/8960.html
The Date object for JavaScript displays the current date and time