forked from ShoroukAziz/notion_widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time_left_in_2021.html
95 lines (81 loc) · 2.31 KB
/
time_left_in_2021.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css2?family=Fjalla+One&display=swap" rel="stylesheet">
<title>Time Left in 2020</title>
<style>
body{
text-align: center;
font-family: 'Fjalla One', sans-serif;
background-color: #fff;
}
.box{
display: inline-block;
display: inline-block;
color: #fff;
padding: 10px;
border-radius: 5px;
}
#days{
background-color:#0f4d4f;
}
#hours{
background-color:#4CAF50;
}
#minutes{
background-color:#76250b;
}
h2{
display: inline-block;
margin-right: 10px;
}
</style>
</head>
<body>
<div id="counter">
<h2>
Time left in 2021
</h2>
<h2 class="box" id="days"></h2>
<h2 class="box" id="hours"></h2>
<h2 class="box" id="minutes"></h2>
</div>
<script>
function CountDownTimer (date) {
left_days = document.getElementById("days");
left_hours = document.getElementById("hours");
left_minutes = document.getElementById("minutes");
end = new Date(date);
_second = 1000;
_minute = _second * 60;
_hour = _minute * 60;
_day = _hour * 24;
}
function showRemaining (){
now = new Date();
distance = end - now;
distance2 = new Date("01/01/2021 00:00 AM") - now
if (distance <= 0 ){
clearInterval (timer)
document.getElementById("counter").innerHTML = "<h2>Nothing! It's Over<h2>";
return
}
else if (distance2 > 0 ){
clearInterval (timer)
document.getElementById("counter").innerHTML = "<h2>2021 Didn't Start yet!</h2>";
return
}
days = Math.floor(distance / _day)
hours = Math.floor((distance % _day) / _hour)
minutes = Math.floor((distance % _hour) / _minute)
left_days.innerHTML = days + " days "
left_hours.innerHTML = hours + " hours "
left_minutes.innerHTML = minutes + " mins "
}
timer = setInterval (showRemaining, 1)
CountDownTimer( "01/01/2022 00:00 AM")
</script>
</body>
</html>