Copy Code code as follows:
function StartTime () {
var today = new Date (); Defining Date Objects
var yyyy = Today.getfullyear (); Returns the year by the getFullYear () method of the Date object
var MM = today.getmonth () + 1; Returns the year by the GetMonth () method of the Date object
var dd = today.getdate (); Returns the year by the GETDATE () method of the Date object
var hh = today.gethours (); Returns an hour by the gethours method of a Date object
var mm = Today.getminutes (); Returns a minute by the Getminutes method of a Date object
var ss = Today.getseconds (); Returns a second by the Getseconds method of a Date object
If the value of minutes or hours is less than 10, add 0 before its value, for example, if the time is 3:20 P.M. 9 seconds, show 15:20:09
MM = Checktime (mm);
DD = Checktime (DD);
MM = Checktime (mm);
SS = Checktime (ss);
Var day; Used to Save Week (Getday () method gets the week number)
if (today.getday () = = 0) Day = "Sunday"
if (today.getday () = = 1) Day = "Monday"
if (today.getday () = = 2) Day = "Tuesday"
if (today.getday () = = 3) Day = "Wednesday"
if (today.getday () = = 4) Day = "Thursday"
if (today.getday () = = 5) Day = "Friday"
if (today.getday () = = 6) Day = "Saturday"
document.getElementById (' Nowdatetimespan '). InnerHTML = yyyy + "-" + mm + "-" + dd + "" + hh + ":" + MM + ":" + SS + "" " + Day;
SetTimeout (' StartTime () ', 1000); Reload the StartTime () method per second
}
function Checktime (i) {
if (I < 10) {
i = "0" + i;
}
return i;
}
Call: <strong> current time: </strong>
<font color= "white" ><span id= "Nowdatetimespan" ></span ></font>