I need to display the month, date and year in addition to the time.
I have tried to create variables for the month, day and year and then get element by ID. Example of how I was trying to do it:
var d = date.getDay();
var mn = date.getmonth();
var y = date.getFullYear();
EDIT: Here is my current code. I have to have a clock as well, but I have successfully coded it.
function showTime(){
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
var session = "AM";
if(h == 0){
h = 12;
}
if(h > 12){
h = h - 12;
session = "PM";
}
h = (h < 10) ? "0" + h : h;
m = (m < 10) ? "0" + m : m;
s = (s < 10) ? "0" + s : s;
var time = h + ":" + m + ":" + s + " " + session;
document.getElementById("MyClockDisplay").innerText = time;
document.getElementById("MyClockDisplay").textContent = time;
setTimeout(showTime, 1000);
}
showTime();
<div id="MyClockDisplay" class="clock"></div>
<div id="Month"></div>
<div id="Day"></div>
<div id="Years"></div>