I’m trying to make a simple live clock and a dd/mm/yy output on page,first function seems to work fine , but unfortunately the second function is not displaying on the page for some reason , tried everything but didn’t helped. I would be grateful if you could help me. Thank you in advance
setInterval(function clock() {
var date = new Date();
var daylist = ["Sunday", "Monday", "Tuesday", "Wednesday ", "Thursday", "Friday", "Saturday"];
var day = date.getDay();
var hour = date.getHours();
var min = date.getMinutes();
var sec = date.getSeconds();
var Part = (hour >= 12) ? 'PM' : 'AM';
if (hour == 0 && Part == 'PM') {
if (minute == 0 && sec == 0) {
hour = 12;
Part = 'Noon'
} else {
hour = 12;
Part = 'PM'
}
}
if (hour > 12) {
hour = hour - 12;
}
var curentday = ('<br></br>' + 'Today is: ' + daylist[day]);
var time = ('Current time is : ' + hour + Part + ': ' + min + ': ' + sec + curentday);
document.getElementById('time').innerHTML = time;
}, 1000);
setInterval(function display() {
var date = new Date();
var date = date.getDate();
var month = date.getMonth() + 1;
var year = date.getFullYear();
var fullDate = ('Current date is :' + date + ':' + month + ':' + year);
document.getElementById('x').innerHTML = fullDate;
}, 1000);
body {
background-color: red;
}
#time {
color: white;
font-size: 3vw;
font-family: Arial, Helvetica, sans-serif;
font-weight: 900;
text-align: center;
margin: 20%;
}
#x {
color: white;
font-size: 3vw;
font-family: Arial, Helvetica, sans-serif;
font-weight: 900;
text-align: center;
margin: 50%;
}
<div id="time"></div>
<div id="x"></div>
>Solution :
this is a modified version of the code, i changed "date" variable to "day" to be more explicit and i changed getDate() by getDay()
setInterval(function display(){
var date = new Date();
var day = date.getDay();
var month = date.getMonth() + 1;
var year = date.getFullYear();
var fullDate =('Current date is :' + day + ':' + month + ':' + year );
document.getElementById('x').innerHTML = fullDate;
}, 1000);
I think this what you looking for