Digital Clock in HTML by Wasim Akhtar

This javascript program display Current Time as Digital Clock

 

Program:

 

<html>

                <head>

                <script type="text/javascript">

                var str="";

                var cd;

                var hr;

                var min;

                var sec;

                var ct="";

                var ap="";

                var cout=0;

                var col="";

                var addcol=100;

                var col1=0;

                var col2=10;

                var col3=20;

                                function displayTime()

                                {

                                                cd=new Date();

                                                hr=cd.getHours();

                                                hr=checkHours(hr);

                                                hr=checkTimes(hr);

                                                min=cd.getMinutes();

                                                min=checkTimes(min);

                                                sec=cd.getSeconds();

                                                sec=checkTimes(sec);

                                                digitalClock();

                                                generateColor();

                                                str="<center><font size=22 color=#"+col+" >"+hr+ct+min+ct+sec+" "+ap+"</font></center>";

                                                document.getElementById("ct").innerHTML=str;

                                                setTimeout("displayTime()",500);

                                }

                                function checkTimes(num)

                                {

                                                if(num<10)

                                                                                num="0"+num;

                                                return num;

                                }

                                function checkHours(nu)

                                {

                                                if(nu>12)

                                                {

                                                                nu=nu-12;

                                                                ap="PM";

                                                }

                                                else

                                                                ap="AM";

                                                return nu;

                                }

                                function digitalClock()

                                {

                                                if(cout==0)

                                                {

                                                                ct=":";

                                                                cout=1;

                                                }

                                                else

                                                                if(cout==1)

                                                                {

                                                                                ct="&nbsp\;";

                                                                                cout=0;

                                                                }

                                }

                                function generateColor()

                                {

                                                col=""+col1+col2+col3;

                                                col1=checkColor(col1);

                                                col1=col1+10;

                                                col2=checkColor(col2);

                                                col2=col2+05;

                                                col3=checkColor(col3);

                                                col3=col2+13;

                                }

                                function checkColor(nm)

                                {

                                                return nm;

                                }

                               

                               

                </script>

                </head>

                <body onload="displayTime()">

                <p id="ct"></p>

                </body>

</html>

No comments:

Post a Comment

If you have any question please let me know

Disable New Unified Theme and Restore Classic UI in Vivaldi Browser

If you use Vivaldi web browser and you don’t like the new “Unified” design introduced in Vivaldi 8.0, this article will help you in disablin...