An instance method in C that dynamically displays the current system time
- 2020-05-10 18:46:41
- OfStack
You can try the following code for dear friends:
Note: here I only have one html tag pair to illustrate the problem, head and so on, add your own.
<html>
<head>
<title> Dynamic display system date and time in web pages </title>
<script language="JavaScript">
function startTime() {
var today = new Date(); // Define a date object
var yyyy = today.getFullYear(); // Passing through the date object getFullYear() Method return year
var MM = today.getMonth() + 1; // Passing through the date object getMonth() Method return year
var dd = today.getDate(); // Passing through the date object getDate() Method return year
var hh = today.getHours(); // Passing through the date object getHours Method return hour
var mm = today.getMinutes(); // Passing through the date object getMinutes Method return minutes
var ss = today.getSeconds(); // Passing through the date object getSeconds Method return second
// If the value of minutes or hours is less than 10 , is added before its value 0 If it's afternoon, for example 3 point 20 points 9 Seconds, it shows 15 : 20 : 09
MM = checkTime(MM);
dd = checkTime(dd);
mm = checkTime(mm);
ss = checkTime(ss);
var day; // Save for week ( getDay() Method to get the week number)
if (today.getDay() == 0) day = " Sunday "
if (today.getDay() == 1) day = " week 1 "
if (today.getDay() == 2) day = " week 2 "
if (today.getDay() == 3) day = " week 3 "
if (today.getDay() == 4) day = " week 4 "
if (today.getDay() == 5) day = " week 5 "
if (today.getDay() == 6) day = " week 6 "
document.getElementById('nowDateTimeSpan').innerHTML = yyyy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss + " " + day;
setTimeout('startTime()', 1000); // every 1 Reload in seconds startTime() methods
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
</script>
</head>
<body onload="startTime()">
OS TIME : <font color="blue"><span id="nowDateTimeSpan"></span></font>
</body>
</html>