-
Notifications
You must be signed in to change notification settings - Fork 0
/
dateObject.html
61 lines (50 loc) · 1.24 KB
/
dateObject.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
body{background-color:#333;}
.clock{color:#F5DEB3;
position:absolute;
transform:translateX(-50%) translateY(-50%);
top:50%;
left:50%;
border:5px solid #222;
border-radius:5px;
padding:15px;
font-size:100px;
font-family:Algerian;
}
</style>
</head>
<body>
<div id="clockDisplay" class="clock"></div>
<script type="text/javascript">
function printTime()
{
var now =new Date();
var h = now.getHours();
var m = now.getMinutes();
var s = now.getSeconds();
var session="AM";
if(h>12)
{
h=h-12;
session="PM";
}
if(h==0)
{
h=12;
}
h = (h < 10) ? "0" + h : h; //also if statements in ternary
m = (m < 10) ? "0" + m : m;
s = (s < 10) ? "0" + s : s;
var time = h+":"+m+":"+s+" "+session;
document.getElementById("clockDisplay").innerText=time;
document.getElementById("clockDisplay").textContent=time;
setTimeout(printTime,1000);
}
printTime();
</script>
</body>
</html>