-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
73 lines (59 loc) · 2.49 KB
/
index.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
<html>
<head>
<title>Timer</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<style>
#days{
color:purple;
}
#hours{
color:green;
}
#minutes{
color:magenta;
}
#seconds{
color:orange;
}
</style>
</head>
<body>
<div class='row'>
<div class='col-sm-12'>
<div style=' margin:auto 20px; text-align:center; font-size:50px;' id ="timevalue"></div>
</div>
</div>
<input type="datetime-local" id = "datetime" >
<button id ="set" onclick ="execute();" class='btn btn-success'>Set</button>
<button id="reset" onclick="Reset();" class='btn btn-danger'>Reset</button>
<div id = 'expired' ></div>
<script>
function Reset(){
clearInterval(a);
document.getElementById("timevalue").innerHTML = "";
document.getElementById("expired").innerHTML = "";
}
function execute(){
// document.getElementById("demo").innerHTML = "Paragraph changed!";
this.a = setInterval(function(){
var endDatetime = document.getElementById("datetime").value;
var start= Date.now(); // Present Time in milliseconds
var end = new Date(endDatetime); // Insert the timer data and time.
var difference = end-start; //Get the difference in milliseconds.
if(difference< 1){
document.getElementById("expired").innerHTML = 'Timer Expired!';
clearInterval(this.a);
}
var days = Math.floor((difference/ (1000*60*60*24)));
var hours = Math.floor((difference%(1000*60*60*24))/(1000*60*60));
var minutes = Math.floor((difference%(1000*60*60))/(1000*60));
var seconds = Math.floor((difference%(1000*60))/(1000));
document.getElementById("timevalue").innerHTML = '<span id="days"> '+days+' Days</span><span id="hours"> '+hours+' Hours</span><span id="minutes"> '+minutes+' Minutes<span><span id="seconds"> '+seconds+ ' Seconds</span>';
},1000);
// clearInterval(a);
// document.getElementById("timevalue").innerHTML = "";
// document.getElementById("expired").innerHTML = "";
}
</script>
</body>
</html>