본문 바로가기

컴퓨터

Javascript Clock Timer Example

Javascript Clock Timer Example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
<script type="text/javascript">
    function showClock()
    {
        var currentDate=new Date();
        var divClock=document.getElementById("divClock");
        var apm=currentDate.getHours();
        if(apm<12)
        {
            apm="AM ";
        }
        else
        {
            apm="PM ";
        }
        
        var msg = "NOW : "+apm +(currentDate.getHours()-12)+" : ";
        msg += currentDate.getMinutes() + " : ";
        msg += currentDate.getSeconds() + "";
        
        divClock.innerText=msg;        
        setTimeout(showClock,1000);
    }
</script>
</head>
<body onload="showClock()">
    <div id="divClock" class="clock"></div>    
</body>
</html>

I have attached simple sample.

 

 

Javascript_Clock.html
0.00MB

 

글이 도움이 되셨다면 하트 공감♥ 꾹!!! 부탁드려용!

로그인은 안해도 할 수 있어용.