0% found this document useful (0 votes)
52 views2 pages

Clock

The document provides HTML and JavaScript code to display a digital clock. The HTML contains two buttons to start and stop the clock, and a div to display the clock. The JavaScript uses a timer to update the div every second with the current time when the start button is clicked, and clears the timer when the stop button is clicked.

Uploaded by

ziasayed786786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views2 pages

Clock

The document provides HTML and JavaScript code to display a digital clock. The HTML contains two buttons to start and stop the clock, and a div to display the clock. The JavaScript uses a timer to update the div every second with the current time when the start button is clicked, and clears the timer when the stop button is clicked.

Uploaded by

ziasayed786786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Write HTML code to design a form that displays two buttons START and

STOP. Write a JavaScript code such that when user clicks on START button,
real time digital clock will be displayed on screen. When user clicks on STOP
button, clock will stop displaying time. (Use Timer methods)
<html>
<head>
<title>Digital Clock</title>
<button onclick="start()">START</button>
<button onclick="stop()">STOP</button>
</head>
<body>
<div id="clock"></div>
<script>
var t;
function updateClock() {
let date = new Date();
let hours = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();
let meridiem = "AM";
if (hours > 12) {
hours -= 12;
meridiem = "PM";
}
if (hours === 0)
hours = 12;
if (minutes < 10)
minutes = "0" + minutes;
if (seconds < 10)
seconds = "0" + seconds;

let time = hours + ":" + minutes + ":" + seconds;


document.getElementById("clock").innerHTML = hours + ":" + minutes + ":" + seconds;
}
function start()
{
t=setInterval(updateClock, 1000);
}

function stop()
{
clearInterval(t);
}
</script>
</body>
</html>

You might also like