-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigitalTime.js
More file actions
32 lines (25 loc) · 956 Bytes
/
Copy pathdigitalTime.js
File metadata and controls
32 lines (25 loc) · 956 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
// function humanReadable(seconds) {
// let hours = Math.floor(seconds / 3600);
// seconds = seconds - 3600 * hours;
// let minutes = Math.floor(seconds / 60);
// seconds = seconds - 60 * minutes;
// hours = twoDigitize(hours);
// minutes = twoDigitize(minutes);
// seconds = twoDigitize(seconds);
// return String(hours) + ":" + String(minutes) + ":" + String(seconds);
// }
// function twoDigitize(time) {
// return (String(time).length == 1) ? "0" + String(time) : time;
// }
function humanReadable(seconds) {
let hours = twoDigitize(Math.floor(seconds / 3600));
seconds = seconds - 3600 * hours;
let minutes = twoDigitize(Math.floor(seconds / 60));
seconds = seconds - 60 * minutes;
seconds = twoDigitize(seconds);
return String(hours) + ":" + String(minutes) + ":" + String(seconds);
}
function twoDigitize(time) {
return String(time).length == 1 ? "0" + String(time) : time;
}
console.log(humanReadable(61));