Digital Clock Project in Javascript
Create a digital clock using HTML, CSS, and javascript.
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Digital Clock</title>
</head>
<body>
<div style="margin-left: 20%;
margin-right: 20%;
margin-top: 5%";
align: center;>
<h1 align="center"
style="color: Green;
font-size: 60px;
font-family: Gill Sans;">
Digital Clock
</h1>
<div class="row" align="center" style="border: 2px solid green ;
border-radius: 20px;
height: 20%;
width: 70%;
margin-top: 20px;
margin-left:10% ;
margin-bottom: 3%;
background-color: Green; ">
<h1 id="clock"
style=" font-family: Gill Sans;
font-size: 60px;
align:center;
color: White;"></h1>
</div>
</div>
<script type="text/javascript">
function showTime() {
var date = new Date();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
var session = "AM"
if (h == 0) { h = 12;} // 12 hr format
if ( h > 12) { h = h - 12; session = "PM"}
//if ( h < 10) { h ="0"+ h; }
h = (h<10)?"0"+h:h;
m = (m < 10)?"0"+m:m;
s = (s < 10)?"0" +s:s;
document.getElementById("clock").innerHTML = h + ":" + m + ":" + s + " " +session;
setTimeout(showTime, 1000);
}
showTime();
</script>
</body>
</html>
Video link:
Comments
Post a Comment