Searching...
Friday, 5 October 2012

Dynamic Clock In Javascript

10:42 pm

Dynamic Clock In Javascript 

Dynamic Clock In Javascript :

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

A Java script program : Dynamic clock

<html>
    <head>
        <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)
            {
                if(i<10)
                    {
                        i="0"+i;
                        }
                       
                        return i;
                       
                    
            }
        </script>
    </head>
    <body onload="startTime()">
        <h1 align="right">
            <span id="txt"></span>
        </h1>
       
    </body>
</html>

Output in IE :

03-09-undefined::undefined:undefined:undefined

Output in FireFox and Chrome :

03-09-112::19:55:13
“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 comments:

  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

    ReplyDelete