Click here to Skip to main content
Licence 
First Posted 30 Sep 2005
Views 16,878
Bookmarked 5 times

Good one and simple example for beginners to display time on browser using java script

By | 30 Sep 2005 | Article
The code demonstrates displaying time using javascript.The javascript function showtime will be called onLoad event of form body tag.settTimeout will keep on dispalying the time for set interval.

Sample Image - JavascriptTime.jpg

Introduction

<script language="javascript">
   function showTime()
   {
    now=new Date();
    var hour=now.getHours();
    var min=now.getMinutes();
    var sec=now.getSeconds();

    if (min<=9) { min="0"+min; }
    if (sec<=9) { sec="0"+sec; }
    if (hour<10) { hour="0"+hour; }  
      
       
    if (hour>12)
     { hour1= hour - 12;}
    else
     hour1 = hour;
    if (hour1<10) { hour1="0"+hour1; } 
    
    var ctime =  hour1 + ":" + min + ":" + sec;
    LABEL1.innerText= ctime;
    setTimeout("showTime()", 1000);
   }
  </script>

 

The above code diplayes the time in a label control named LABEL1.
you can create a simple html page and add a label and name it LABEL1.
Then add the above script into header section of the html.
Try accessing the page. You can also down load the sample code.

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

ManjunathR

Web Developer

India India

Member

fgdf

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 30 Sep 2005
Article Copyright 2005 by ManjunathR
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid