-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
97 lines (79 loc) · 2.07 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const months = [
"January",
"Febuary",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
];
const weekdays = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
const ticker = document.querySelector(".ticker");
const deadline = document.querySelector(".deadline");
const items = document.querySelectorAll(".deadline-format h4");
let futureDate = new Date (2040,11,31,23,59,59);
//console.log(futureDate);
//for current date remove specified values in ()
const year = futureDate.getFullYear();
const hours = futureDate.getHours();
const minutes = futureDate.getMinutes();
let month = futureDate.getMonth();
//console.log(months[month]);
month = months[month];
const date = futureDate.getDate ();
const weekday = weekdays [futureDate.getDay()];
//console.log(weekday);
ticker.textContent = `The Final Countdown to ${weekday}, ${date}st ${month}, ${year} ${hours}:${minutes} has Commenced...`;
ticker.style.fontSize = "30px";
//future time in ms
const futureTime = futureDate.getTime();
//console.log(futureTime);
function getRemainingTime(){
const today = new Date().getTime();
//console.log(today);
const t = futureTime - today;
//1s = 1000ms
//1m = 60s
//1hr = 60min
//1d = 24 hrs
//value in ms
const oneDay = 24 * 60 * 60 * 1000;
const oneHour = 60 * 60 * 1000;
const oneMinute = 60 * 1000;
//calculate all values
let days = t / oneDay;
days = Math.floor(days);
let hours = Math.floor ((t % oneDay) / oneHour);
let minutes = Math.floor((t % oneHour) / oneMinute);
let seconds = Math.floor((t % oneMinute) / 1000);
//set values array;
const values = [days, hours, minutes, seconds];
function format (item){
if (item <10) {
return (item = `0${item}`);
}
return item;
}
items.forEach(function (item, index) {
item.innerHTML = format(values[index]);
});
if (t<0) {
clearInterval (countdown);
deadline.innerHTML = `<h3 class="expired">Too Late.. Time's up!</h3>`;
}
}
let countdown = setInterval(getRemainingTime,1000);
getRemainingTime();