User:Mirror Zero/Clock
From Destinypedia, the Destiny wiki
// Display current local date and time in an element with ID "localTime" document.addEventListener("DOMContentLoaded", function () {
var el = document.getElementById("localTime");
if (el) {
function updateTime() {
var now = new Date();
// Format: YYYY-MM-DD HH:MM:SS
var formatted = now.getFullYear() + "-" +
String(now.getMonth() + 1).padStart(2, '0') + "-" +
String(now.getDate()).padStart(2, '0') + " " +
String(now.getHours()).padStart(2, '0') + ":" +
String(now.getMinutes()).padStart(2, '0') + ":" +
String(now.getSeconds()).padStart(2, '0');
el.textContent = formatted;
}
updateTime();
setInterval(updateTime, 1000); // Update every second
}
});