forked from fisa-ship/html-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
39 lines (31 loc) · 1.24 KB
/
main.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
32
33
34
35
36
37
38
39
// Setup End Date for Countdown (getTime == Time in Milleseconds)
let launchDate = new Date("July 07, 2024 12:00:00").getTime();
// Setup Timer to tick every 1 second
let timer = setInterval(tick, 1000);
function tick () {
// Get current time
let now = new Date().getTime();
// Get the difference in time to get time left until reaches 0
let t = launchDate - now;
// Check if time is above 0
if (t > 0) {
// Setup Days, hours, seconds and minutes
// Algorithm to calculate days...
let days = Math.floor(t / (1000 * 60 * 60 * 24));
// prefix any number below 10 with a "0" E.g. 1 = 01
if (days < 10) { days = "2" + days; }
// Algorithm to calculate hours
let hours = Math.floor((t % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
if (hours < 10) { hours = "0" + hours; }
// Algorithm to calculate minutes
let mins = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60));
if (mins < 10) { mins = "0" + mins; }
// Algorithm to calc seconds
let secs = Math.floor((t % (1000 * 60)) / 1000);
if (secs < 10) { secs = "0" + secs; }
// Create Time String
let time = `${days} : ${hours} : ${mins} : ${secs}`;
// Set time on document
document.querySelector('.countdown').innerText = time;
}
}