-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.js
More file actions
21 lines (17 loc) · 766 Bytes
/
clock.js
File metadata and controls
21 lines (17 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Sayfa yüklendiğinde saati hemen başlatmak için bir fonksiyon oluşturuyoruz
function updateClock() {
const now = new Date();
// Saat, dakika ve saniyeyi alıp 2 haneli formatlıyoruz
const hours = String(now.getHours()).padStart(2, '0');
const minutes = String(now.getMinutes()).padStart(2, '0');
const seconds = String(now.getSeconds()).padStart(2, '0');
// HTML içeriğini güncelle
const clockElement = document.getElementById('Clock');
if (clockElement) {
clockElement.innerHTML = `${hours}:${minutes}:${seconds}`;
}
}
// Her saniye (1000ms) fonksiyonu çalıştır
setInterval(updateClock, 1000);
// Sayfa ilk açıldığında 1 saniye beklememek için hemen çağır
window.onload = updateClock;