-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
101 lines (74 loc) · 2.13 KB
/
app.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
98
99
100
101
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
const weekdays = [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
];
const futureDate = document.querySelector("#future-date")
const countDown = document.querySelectorAll(".count-down h2")
const sayac = document.querySelector(".count-down")
// new date assaignt
let fDate = new Date()
let fyear = fDate.getFullYear();
let fmonth = fDate.getMonth()
let fday = fDate.getDate()
// future day start
const newDate = new Date(fyear,fmonth,fday+10,11,30,0)
let year = newDate.getFullYear()
let month = newDate.getMonth()
let day = newDate.getUTCDate()
let hour = newDate.getHours()
let min = newDate.getMinutes()
let sec = newDate.getSeconds()
month = months[month]
week = weekdays[newDate.getDay()]
futureDate.innerHTML = `giveaway ends on ${week} ,${day} ${month} ${year}, ${hour}:${min}am`
// future day end
// remainedTime start
function remainedTime() {
let newDatesec = newDate.getTime()
let today = new Date().getTime()
let downDay = Math.floor((newDatesec-today)/(24*60*60*1000))
let downHour= (Math.floor((newDatesec-today)/(60*60*1000))) % 24
let downMin = (Math.floor((newDatesec-today)/(60*1000))) %60
let downSec = (Math.floor((newDatesec-today)/(1000))) % 60
// set value in array
const timeArray = [downDay,downHour,downMin,downSec]
function edit(countDown){
if(countDown<10) {
return countDown = `0${countDown}`
}
return countDown
}
countDown.forEach((item,i) =>
item.innerHTML = edit(timeArray[i])
)
if((newDatesec-today)<0) {
clearInterval(remainedTime)
sayac.innerHTML = `<h2 class="finished">We are sorry, Giveaway has expired..</h2>`
}
// 1sn = 1000ms
// 1min = 60sn
// 1hour = 60min
// 1day = 24hour
// 1month =
}
setInterval(remainedTime,1000)
remainedTime()