-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (24 loc) · 863 Bytes
/
script.js
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
'use strict';
function countdown(due) {
const now = new Date();
const rest = due.getTime() - now.getTime();
const sec = Math.floor(rest / 1000) % 60;
const min = Math.floor(rest / 1000 / 60) % 60;
const hours = Math.floor(rest / 1000 / 60 / 60) % 24;
const days = Math.floor(rest / 1000 / 60 / 60 / 24);
const count = [days, hours, min, sec];
return count;
}
let goal = new Date(2025, 4, 3);
function recalc() {
const counter = countdown(goal);
document.getElementById('day').textContent = counter[0];
document.getElementById('hour').textContent = counter[1];
document.getElementById('min').textContent = String(counter[2]).padStart(2, '0');
document.getElementById('sec').textContent = String(counter[3]).padStart(2, '0');
refresh();
}
function refresh() {
setTimeout(recalc, 1000);
}
recalc();