Javascript simple clock

Create a simple function that get the client time (hours:minutes:seconds) and prints it in the div:


<script type="text/javascript">
function getTime() {
var currentDate = new Date();
var hour = currentDate.getHours();
var min = currentDate.getMinutes();
var sec = currentDate.getSeconds();
var currentTime = hour + ":" + min + ":" + sec;
document.getElementById('clock').innerHTML = currentTime;
}
setInterval("getTime()", 1000);
</script>
<div id="clock"></div>

Leave a Reply

Your email address will not be published. Required fields are marked *