Nandakumar Edamana
Share on:
@ R t f

JavaScript Digital Clock

Code

&lthtml&gt
    &lthead&gt
        &lttitle&gtJavaScript Digital Clock&lt/title&gt
        &ltstyle&gt
            body {
                text-align: center;
            }
        
            #pTime {
                font-family: monospace;
                font-weight: bold;
                font-size: 2em;
            }
        &lt/style&gt
        &ltscript&gt
            var pTime;
            
            function onEachSecond() {
                date = new Date();
                pTime.innerHTML = date.toLocaleTimeString();
            }
            
            function onLoaded() {
                pTime = document.getElementById("pTime");
                setInterval(onEachSecond, 1000);
                onEachSecond();
            }
        &lt/script&gt
    &lt/head&gt
    
    &ltbody onload="onLoaded()"&gt
        &lth1&gtJavaScript Digital Clock&lt/h1&gt
        &ltp id="pTime" /&gt
    &lt/body&gt
&lt/html&gt