I'm making a website with a digital clock and i wanna display some text on the side like this "Sat, Dec ,4". The code for the digital clock works but the day/month/date are not being displayed at all.
function currenTime() {
var dateNow = new Date();
var h = dateNow.getHours();
var m = dateNow.getMinutes();
var s = dateNow.getSeconds();
let days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
let months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
let day = days[dateNow.getDay()];
let date = dateNow.getDate();
let month = months[dateNow.getMonth()];
let calendarD = date + ", " + month + ", " + day;
document.getElementById("d").innerText = calendarD;
/*SESSION CODE*/
var session = "";
if (h >= 12) {
session = "PM"
} else {
session = "AM";
}
/* 24 to 12 Hour format display */
if (h > 12) {
h -= 12;
}
if (h == 0) {
h = 12;
}
/* ADD 0 TO MINUTES,HOURS,SECONDS*/
if (h < 10) {
h = "0" + h;
}
if (m < 10) {
m = "0" + m;
}
if (s < 10) {
s = "0" + s;
}
var timeNow = h + ":" + m + ":" + s + " " + session;
document.getElementById("clock").innerText = timeNow;
setTimeout(currenTime, 1000);
}
<body onload="currenTime()">
<div id="clock" ></div>
<p id="d"></p>
</body>
As you can see i wanna place the day,month and date inside the paragraph tag,but the values are never displayed.
from Recent Questions - Stack Overflow https://ift.tt/3IeorUR
https://ift.tt/eA8V8J
No comments:
Post a Comment