-
Notifications
You must be signed in to change notification settings - Fork 0
/
timetoland.html
executable file
·86 lines (76 loc) · 2.69 KB
/
timetoland.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
<!DOCTYPE html>
<html>
<head>
<title>Time til Bev Lands</title>
<script>
var end = new Date(2016, 8, 8, 13, 29);
var t = null;
function tick(end) {
var difms = (end) - (new Date());
// if (difms <= 0) { clearInterval(t); }
var daysFl = difms / 1000 / 60 / 60 / 24;
var days = Math.floor(daysFl);
var hoursFl = 24 * (daysFl - days);
var hours = Math.floor(hoursFl);
var minutesFl = 60 * (hoursFl - hours);
var minutes = Math.floor(minutesFl);
var secondsFl = 60 * (minutesFl - minutes);
var seconds = Math.floor(secondsFl);
return {
'total': difms,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
function update() {
// console.log('update()');
var time = tick(end);
var str = time.days.toString() + 'd:' + time.hours.toString() + 'h:' + time.minutes.toString() + 'm:' + time.seconds.toString() + 's';
document.getElementById('daysSpan').innerHTML = time.days.toString();
document.getElementById('hoursSpan').innerHTML = time.hours.toString();
document.getElementById('minutesSpan').innerHTML = time.minutes.toString();
document.getElementById('secondsSpan').innerHTML = time.seconds.toString();
}
function main_loop() {
t = setInterval(update, 1000);
}
</script>
<style>
body { font-size: 16px; }
.clrFix { clear: both; }
.timer { width: 20em; background-color: #888; padding: 0.1em; }
.timerBox { width: 20%; background-color: #56F; float: left; text-align: center; margin: 2%; padding: 0.5%; }
.label { font-size: 0.8em; }
.timeValue { font-size: 1.4em; font-weight: 600; }
.button { text-align: center; float: left; width: 20%; padding: 0.1em; margin: 0.2em 14%; cursor: pointer; }
.stop { background-color: #D00; }
.start { background-color: #0D0; }
</style>
</head>
<body onload="main_loop()">
<div class="timer">
<span class="button start" onclick="main_loop()">Start</span>
<span class="button stop" onclick="clearInterval(t)">Stop</span>
<span class="clrFix"></span>
<div id="daysDiv" class="timerBox">
<span class="timeValue" id="daysSpan"></span><br>
<span class="label">Days</span>
</div>
<div id="hoursDiv" class="timerBox">
<span class="timeValue" id="hoursSpan"></span><br>
<span class="label">Hours</span>
</div>
<div id="minutesDiv" class="timerBox">
<span class="timeValue" id="minutesSpan"></span><br>
<span class="label">Minutes</span>
</div>
<div id="secondsDiv" class="timerBox">
<span class="timeValue" id="secondsSpan"></span><br>
<span class="label">Seconds</span>
</div>
<div class="clrFix"></div>
</div>
</body>
</html>