-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (28 loc) · 925 Bytes
/
index.js
File metadata and controls
33 lines (28 loc) · 925 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
const NINE_HOURS_MILLISECONDS = 32400000;
const CALCULATE_TIME = document.querySelector(".js-calculate-day");
function getTime() {
// Don't delete this.
const xmasDay = new Date("2020-11-21:00:00:00+0900");
const today = new Date();
const gap = xmasDay.getTime() - today.getTime();
const day = Math.floor(gap / (1000 * 60 * 60 * 24));
const hour = Math.floor((gap - day * 1000 * 60 * 60 * 24) / (1000 * 60 * 60));
const minite = Math.floor(
(gap - day * 1000 * 60 * 60 * 24 - hour * 1000 * 60 * 60) / (1000 * 60)
);
const second = Math.floor(
(gap -
day * 1000 * 60 * 60 * 24 -
hour * 1000 * 60 * 60 -
minite * 1000 * 60) /
1000
);
CALCULATE_TIME.innerHTML = `${day}d ${hour < 10 ? `0${hour}` : hour}h ${
minite < 10 ? `0${minite}` : minite
}m ${second < 10 ? `0${second}` : second}s `;
}
function init() {
getTime();
setInterval(getTime, 1000);
}
init();