-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (18 loc) · 756 Bytes
/
script.js
File metadata and controls
23 lines (18 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function updateClock () {
//Take all time data
var totalTime = new Date();
//Extract required data
var currentHours = totalTime.getHours();
var currentMinutes = totalTime.getMinutes();
var currentSeconds = totalTime.getSeconds();
//12hr clock
currentHours = (currentHours > 12 ? currentHours - 12 : currentHours);
//Padding with 0
currentHours = (currentSeconds < 10 ? "0" : "") + currentHours;
currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;
//Format data
var clock1 = currentHours + ":" + currentMinutes + ":" + currentSeconds;
//Print data
document.getElementById("clock1").innerHTML = clock1;
}