Skip to content

Commit

Permalink
update date and time in real time
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallDoesCoding authored Jul 7, 2022
1 parent 03291c7 commit 21035d8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
var datetime = new Date();
console.log(datetime);
document.getElementById("time").textContent = datetime; //it will print on html page
function refreshTime() {
const timeDisplay = document.getElementById("time");
const dateString = new Date().toLocaleString();
const formattedString = dateString.replace(", ", " - ");
timeDisplay.textContent = formattedString;
}
setInterval(refreshTime, 1000);

0 comments on commit 21035d8

Please sign in to comment.