Friday, 5 October 2012

Dynamic Clock In Javascript

10:42 pm

Dynamic Clock In Javascript 

Dynamic Clock In Javascript :

    <meta http-equiv="refresh" content="1" url = "index.php"/>
 echo "<h1>";
 $d = date("H:i:s");
 echo $d;

A Java script program : Dynamic clock

        <script type="text/javascript">
            function startTime(){
                var today = new Date();
                var h = today.getHours();
                var m = today.getMinutes();
                var s = today.getSeconds();
                var d = today.getDate();
                var mon = today.getMonth();
                var y = today.getYear();
                m = checkTime(m);
                h = checkTime(h);
                s = checkTime(s);
                d = checkTime(d);
                mon = checkTime(mon);
                y = checkTime(y);
                document.getElementById('txt').innerHTML = d+"-"+mon+"-"+y+"::"+h+":" +m+":"+s;
                t = setTimeout('startTime()');
            function checkTime(i)
                        return i;
    <body onload="startTime()">
        <h1 align="right">
            <span id="txt"></span>

Output in IE :


Output in FireFox and Chrome :

“date is a builtin class of javascript used for working with date and time.”new” operator is used for creating an object of a class in JS.
 Var d = new Date();
 In Javascript date . the month is ranging from 0 to 11 where 0 is january and 11 is december and day of the week is ranging from 0 to 6 where 0 is Sunday and 6 is Saturday.


  1. Very informative and It was an awesome post. I love reading your fantastic content. Thanks for sharing it with us. We are so greatful to your sharing.Rapid PHP 2018