Copy the code code as follows:
function startTime() {
var today = new Date(); //Define date object
var yyyy = today.getFullYear(); //Return the year through the getFullYear() method of the date object
var MM = today.getMonth() + 1; //Return the year through the getMonth() method of the date object
var dd = today.getDate(); //Return the year through the getDate() method of the date object
var hh = today.getHours(); //Return the hour through the getHours method of the date object
var mm = today.getMinutes(); //Return minutes through the getMinutes method of the date object
var ss = today.getSeconds(); //Return seconds through the getSeconds method of the date object
// If the value of the minute or hour is less than 10, add 0 in front of its value. For example, if the time is 3:20:9, it will display 15:20:09
MM = checkTime(MM);
dd = checkTime(dd);
mm = checkTime(mm);
ss = checkTime(ss);
var day; //Used to save the day of the week (the getDay() method gets the day of 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 every 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>