-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
73 lines (61 loc) · 1.6 KB
/
Copy pathapp.js
File metadata and controls
73 lines (61 loc) · 1.6 KB
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
const years = [
"Januari",
"Febuari",
"Maret",
"April",
"Mei",
"Juni",
"Juli",
"Agustus",
"September",
"Oktober",
"November",
"Desember",
];
const weekdays = [
"Minggu",
"Senin",
"Selasa",
"Rabu",
"Kamis",
"Jum'at",
"Sabtu",
];
const giveaway = document.querySelector(".giveaway");
const deadline = document.querySelector(".deadline-formal");
const timeouts = document.querySelectorAll(".deadline-format h4");
let futureDate = new Date(2025, 2, 28, 1, 0, 0);
console.log(futureDate);
const year = futureDate.getFullYear();
const month = years[futureDate.getMonth()];
const date = futureDate.getDate();
const day = weekdays[futureDate.getDay()];
console.log(month);
giveaway.textContent = `Giveaway berakhir pada ${day} ${date} ${month} ${year}`;
function getRemainingTime() {
const futureTime = futureDate.getTime();
const today = new Date().getTime();
const remaining = futureTime - today;
// 1s = 1000 ms
// 1m = 60s
// 1h = 60m
// 1d = 24h
const oneDay = 24 * 60 * 60 * 1000;
const oneHour = 60 * 60 * 1000;
const oneMinute = 60 * 1000;
const oneSecs = 1000;
const days = Math.floor(remaining / oneDay);
const hours = Math.floor((remaining % oneDay) / oneHour);
const minutes = Math.floor((remaining % oneHour) / oneMinute);
const secs = Math.floor((remaining % oneMinute) / oneSecs);
const values = [days, hours, minutes, secs];
timeouts.forEach((timeout, index) => {
timeout.innerHTML = values[index];
if (remaining < 0) {
timeout.parentElement.parentElement.remove()
}
});
}
setInterval(() => {
getRemainingTime();
}, 1000);