-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·40 lines (32 loc) · 1009 Bytes
/
Copy pathscript.js
File metadata and controls
executable file
·40 lines (32 loc) · 1009 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
37
38
39
40
function showTime() {
let date = new Date();
let hour = date.getHours(); // 0 - 23
let minute = date.getMinutes(); // 0 - 59
let second = date.getSeconds(); // 0 - 59
let session = 'AM';
if (hour == 0) {
hour = 12;
}
if (hour > 12) {
hour = hour - 12;
session = 'PM';
}
hour = hour < 10 ? '0' + hour : hour;
minute = minute < 10 ? '0' + minute : minute;
second = second < 10 ? '0' + second : second;
let time = hour + ':' + minute + ':' + second + ' ' + session;
document.getElementById('digitalClock').innerText = time;
document.getElementById('digitalClock').textContent = time;
// Add sound effect
let clickSound = new Audio();
clickSound.src = 'clockTicking.mp3';
clickSound.play();
setTimeout(showTime, 1000);
}
function init() {
var date = new Date();
var options = { day: 'numeric', month: 'long', year: 'numeric' };
document.querySelector('#date').innerHTML = date.toLocaleString('en-US', options);
}
window.onload = init;
showTime();