The
let theDate = new Date();
// Result: Sat Mar 07 2020 10:19:08 GMT-0500 (Eastern Standard Time)
let theLocalTIme = theDate.toLocaleTimeString();
// Result: 10:19:08 AM
let theLocalDate = theDate.toLocaleDateString();
// Result: 3/7/2020
let theLocalBoth = theDate.toLocaleString();
// Result: 3/7/2020, 10:19:08 AM
Time Constant Update
Constantly updating the time, like a clock would, can be achieved with the simpler setInterval() function
function constantUpdate() {
let timeHolder = document.getElementById("constant-time");
let cntr = 0;
setInterval(function() {
cntr++;
let thisDateTime = new Date();
let thisLocalTIme = thisDateTime.toLocaleTimeString();
timeHolder.innerText = thisLocalTIme;
}, 1000)
}
let currentTime = constantUpdate();
2:19:37 PM













