-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.html
53 lines (41 loc) · 1.11 KB
/
test.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
<input type="datetime-local" id="starttime">
<input type="datetime-local" id="finishtime">
<button onclick="getTime()">시간차이 구하귀</button>
<div id="app">
</div>
<script>
var gap = 0;
var myInterval;
function getTime(){
let start = document.getElementById("starttime");
let finish = document.getElementById("finishtime");
let app = document.getElementById("app");
let st = new Date(start.value);
let fin = new Date(finish.value);
if(st > fin)
return
gap = Math.floor((fin - st) / 1000);
app.innerText = gap.toDate();
myInterval = setInterval(timeUpdate, 1000);
}
function timeUpdate(){
let app = document.getElementById("app");
gap = gap - 1;
app.innerText = gap.toDate();
if(gap === 0){
clearInterval(myInterval);
alert("시간 끝!!")
}
}
Number.prototype.toDate = function(){
var t = this
var s = t % 60
t = Math.floor(t/60)
var m = t % 60
t = Math.floor(t/60)
var h = t % 24
t = Math.floor(t/24)
var d = t
return "Day : " + d + " Hour : " + h + " Min : " + m + " Sec : " + s
}
</script>