This article mainly introduces the JS instance code for real-time page update. If you need it, refer to it.
The Code is as follows:
Function startTime (){
Var today = new Date (); // defines the Date object
Var yyyy = today. getFullYear (); // returns the year by using the getFullYear () method of the date object.
Var MM = today. getMonth () + 1; // returns the year using the getMonth () method of the date object.
Var dd = today. getDate (); // returns the year using the getDate () method of the date object.
Var hh = today. getHours (); // returns the hour through the getHours method of the date object
Var mm = today. getMinutes (); // returns the minute through the getMinutes method of the date object
Var ss = today. getSeconds (); // returns the second through the getSeconds method of the date object
// If the minute or hour value is less than 10, add 0 before the value. For example, if the time is 03:20:09 P.M., 15:20:09 is displayed.
MM = checkTime (MM );
Dd = checkTime (dd );
Mm = checkTime (mm );
Ss = checkTime (ss );
Var day; // used to save the week (getDay () method to get the day of the week)
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 every second.
}
Function checkTime (I ){
If (I <10 ){
I = "0" + I;
}
Return I;
}
Call:Current Time: