digital clock using javascript

 <div id="clock"></div>

<script type="text/javascript">

setInterval(displayclock, 500);

function displayclock(){

var time = new Date();

var hrs = time.getHours();

var min = time.getMinutes();

var sec = time.getSeconds();

if(hrs>12){

hrs = hrs -12;

}

if(hrs==0){

hrs =12;

}


//if the digit is less than 10 then it will  show the number with 0 in prefix

if(hrs<10){

hrs = '0' + hrs;

}

if(min<10){

min = '0' + min;

}

if(sec<10){

sec = '0' + sec;

}


document.getElementById('clock').innerHTML = hrs + ':'+ min + ':' + sec;


}


</script>

Comments

Popular posts from this blog

Generative AI Model for text summarization

maintext/ react

Resume description for AI/ ML Developer