-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.php
39 lines (34 loc) · 1.24 KB
/
countdown.php
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Shaw Academy Practical Countdown Exercise</title>
</head>
<body>
<p id="hours"></p>
<p id="minutes"></p>
<p id="seconds"></p>
<script>
var start = new Date(2017, 2, 20, 23); //fix this to current year mo date hours
updateCountdown("hours","minutes","seconds");
setInterval(function(){updateCountdown("hours","minutes","seconds")}, 1000);
function updateCountdown(hoursId,minutesId,secondsId) {
var count = timeRemaining();
document.getElementById(hoursId).innerHTML = count.hours;
document.getElementById(minutesId).innerHTML = count.minutes;
document.getElementById(secondsId).innerHTML = count.seconds;
}
function timeRemaining() {
var now = new Date();
var timeLeft = start.getTime() - now.getTime(); //in milliseconds
var hours = timeLeft / (1000 * 60 * 60);
hours = Math.floor(hours);
var minutes = timeLeft / (1000 * 60) - hours * 60;
minutes = Math.floor(minutes);
var seconds = timeLeft / (1000) - hours * 60 * 60 - minutes * 60;
seconds = Math.floor(seconds);
return {hours: hours, minutes: minutes, seconds: seconds};
}
</script>
</body>
</html>