Repository navigation
Expand file tree
/
Copy pathcountup.js
More file actions
60 lines (44 loc) · 2.11 KB
/
Copy pathcountup.js
File metadata and controls
60 lines (44 loc) · 2.11 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
// Set the date we're counting down to
var countUpDate = new Date("Oct 05, 2022 02:34:00").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
//**DEV ENTRY-------------------------------------------------
//var now = 1670781540000
//**END DEV ENTRIES------------------------------------------
// Find the distance between now and the count down date
var distance = now - countUpDate;
//**DEV ENTRIES--------------------------------------------------------
//document.getElementById("distance").innerHTML = distance
//var rightnow = now;
//document.getElementById("now").innerHTML = now
//var duedate = countDownDate;
//document.getElementById("duedate").innerHTML = countDownDate
//**END DEV----------------------------------------------------------
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="countdown"
document.getElementById("countup").innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If time is passed 10/12/2022 18:00:00, (within 24 hours) then only print hours
if (distance < 86400000) {
document.getElementById("countup").innerHTML = hours + "h " + minutes + "m " + seconds + "s ";
}
// If time is passed 11/12/2022 17:00:00, (within 1 hour) then only print minutes
if (distance < 3600000) {
document.getElementById("countup").innerHTML = minutes + "m " + seconds + "s ";
}
// If time is passed 11/12/2022 17:59:00, (within 1 minute) then only print seconds
if (distance < 60000) {
document.getElementById("countup").innerHTML = seconds + "s ";
}
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("countup").innerHTML = "Treasure the moments";
}
}, 1000);