-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsClock.js
More file actions
36 lines (30 loc) · 971 Bytes
/
Copy pathJsClock.js
File metadata and controls
36 lines (30 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Developed by Amin Arjmand
Email: aminarj2000@gmail.com | Site: aminarjmand.com | GitHub: @sibche2013
*/
let clockInterval;
const clockElement = document.getElementById("cas");
// Run clock immediately on load
jsClock();
startClock();
function jsClock() {
const date = new Date();
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
clockElement.innerHTML = `${hours}:${minutes}:${seconds}`;
}
function startClock() {
clockInterval = setInterval(jsClock, 1000);
}
function toggleClock() {
if (clockInterval) {
clearInterval(clockInterval);
clockInterval = null;
clockElement.classList.add("stopped");
} else {
jsClock(); // Update immediately on resume
startClock();
clockElement.classList.remove("stopped");
}
}