RearangeClockMiniProjectAndOthers
This commit is contained in:
12
MiniProjects/DigitalClock/clock.js
Normal file
12
MiniProjects/DigitalClock/clock.js
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
function updateClock(){
|
||||
const time = new Date();
|
||||
const hours = time.getHours().toString().padStart(2, "0");
|
||||
const minutes = time.getMinutes().toString().padStart(2, "0");
|
||||
const seconds = time.getSeconds().toString().padStart(2, "0");
|
||||
const time_string = `${hours}:${minutes}:${seconds}`;
|
||||
document.getElementById("clock").textContent = time_string;
|
||||
}
|
||||
|
||||
updateClock();
|
||||
setInterval(updateClock, 1000);
|
Reference in New Issue
Block a user