-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
57 lines (42 loc) · 1.56 KB
/
script.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
let sub = document.getElementById("sub");
let clr = document.getElementById("clr");
let cont = document.getElementById("cont");
let uTimeEl = document.getElementById("uTime");
sub.addEventListener("click", ()=>{
let uTime = uTimeEl.value;
let uMilli = new Date(uTime).getTime();
localStorage.setItem("uMilli",uMilli)
localStorage.setItem("uTime",uTime)
})
setInterval(() => {
let guMilli = localStorage.getItem("uMilli");
if (guMilli) {
let now = new Date().getTime();
let interval = (now - guMilli)/1000;
let days = Math.floor(interval/(60*60*24));
let left1 = interval%(60*60*24);
let hours = Math.floor(left1/(60*60));
let left2 = left1%(60*60);
let minutes = Math.floor(left2/60);
let seconds = Math.floor(left1%60);
if (interval>0) {
cont.style.display="block";
cont.innerHTML= `${days} days ${hours} hours ${minutes} minutes ${seconds} seconds`;
} else if(interval<0){
cont.style.display="block";
cont.innerHTML="The day will come in future...."
} else{
cont.style.display="none";
}
}
}, 1000);
let guTime = localStorage.getItem("uTime");
if (guTime) {
uTimeEl.value = guTime;
}
clr.addEventListener("click", ()=>{
localStorage.clear();
cont.innerHTML="";
uTimeEl.value="";
cont.style.display="none";
})