Programming Tutorials

Javascript to display client date and time on webpage

By: [email protected] in Javascript Tutorials on 2009-12-26  

Use below code to display client date and time on web page.


    <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
    <STYLE type=text/css>
        .mainheading {
            FONT-WEIGHT: bold;
            FONT-SIZE: 14px;
            COLOR: #000000;
            FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

        .mainbody {
            FONT-SIZE: x-small;
            FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
            LIST-STYLE-TYPE: square

        .maintitle {
            FONT-WEIGHT: bold;
            FONT-SIZE: medium;
            FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif

<BODY text=#000000 bgColor=#ffffff leftMargin=1 topMargin=0 onload="setFromTo();">
    <TABLE cellSpacing=3 cellPadding=0 width=770 border=0>
                <TD width=77>&nbsp;</TD>
                <TD class=mainheading>

                <TD colSpan=2>
                    <HR color=green>
                <TD width=77>&nbsp;</TD>
                    <P>Today's Date & Time on Client machine </P>
                    <SCRIPT LANGUAGE="JavaScript">
                        tday  =new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
                        tmonth=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
                        function GetClock(){
                        d = new Date();
                        nday   = d.getDay();
                        nmonth = d.getMonth();
                        ndate  = d.getDate();
                        nyeara = d.getYear();
                        nhour  = d.getHours();
                        nmin   = d.getMinutes();
                        nsec   = d.getSeconds();
                            if(nhour ==  0) {ap = " AM";nhour = 12;}
                        else if(nhour <= 11) {ap = " AM";}
                        else if(nhour == 12) {ap = " PM";}
                        else if(nhour >= 13) {ap = " PM";nhour -= 12;}
                        if(nmin <= 9) {nmin = "0" +nmin;}
                        if(nsec <= 9) {nsec = "0" +nsec;}
                        document.getElementById('clockbox').innerHTML=""+tday[nday]+", "+tmonth[nmonth]+" "+ndate+", "+nyeara+" "+nhour+":"+nmin+":"+nsec+ap+"";
                        setTimeout("GetClock()", 1000);
                    <div id="clockbox"></div>
                    <P> Admin</P>
                <TD width="77">&nbsp;</TD>

                <TD colSpan="2">


Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in Javascript )

Latest Articles (in Javascript)