Results 1 to 6 of 6

Thread: Create A Clock With Javascript

  1. #1
    Join Date
    Nov 2009
    Posts
    877

    Create A Clock With Javascript

    Hello, I am learning java script by own. And I want to create a script which can provide me clock. If anybody knows code for this script then please provide me that. If you know the sources then also provide me. Suggest me some good books for basic javascrpt understanding.

  2. #2
    Join Date
    May 2008
    Posts
    2,015

    Re: Create A Clock With Javascript

    I think you may need to use javascript books below to get this solution :
    • JavaScript Programmer's Reference
    • Beginning JavaScript
    • JavaScript: The Definitive Guide
    • Instant JavaScript
    • JavaScript Application Cookbook
    • Learn Advanced JavaScript Programming

  3. #3
    Join Date
    Apr 2008
    Posts
    2,010

    Re: Create A Clock With Javascript

    The script below will provide you A clock in Javascript:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function time()
    {
    var now=new Date();
    var hr=now.getHours();
    var minute=now.getMinutes();
    var s=now.getSeconds();
    minute=checkTime(minute);
    seconds=checkTime(seconds);
    document.getElementById('txt').innerHTML=h+":"+minute+":"+seconds;
    t=setTimeout('time()',500);
    }
    
    function checkTime(i)
    {
    if (i<10)
      {
      i="0" + i;
      }
    return i;
    }
    </script>
    </head>
    
    <body onload="time()">
    <div id="txt"></div>
    </body>
    </html>

  4. #4
    Join Date
    May 2008
    Posts
    2,302

    Re: Create A Clock With Javascript

    I have created the script below for getting clock in javascript. You canmake use of it.
    Code:
    <script type="text/javascript">
    <!--
    function updateClock ( )
    {
      var currt = new Date ( );
      var currh = currt.getHours ( );
      var currm= currt.getMinutes ( );
      var currs = currt.getSeconds ( );
      currm= ( currm< 10 ? "0" : "" ) + currm;
      currs = ( currs < 10 ? "0" : "" ) + currs;
      var timeOfDay = ( currh < 12 ) ? "AM" : "PM";
      currh = ( currh > 12 ) ? currh - 12 : currh;
      currh = ( currh == 0 ) ? 12 : currh;
      var currtString = currh + ":" + currm+ ":" + currs + " " + timeOfDay;
      document.getElementById("clock").firstChild.nodeValue = currtString;
    }
    // -->
    </script>

  5. #5
    Join Date
    Oct 2005
    Posts
    2,394

    Re: Create A Clock With Javascript

    Use the methods below to create your Javascript for getting the clock:
    1. getDate() - For returning day of month
    2. getDay() - For returning day of week
    3. getHours() - For returning hour
    4. getMinutes() - For returning minutes
    5. getSeconds() - For returning seconds
    6. getMonth() - For returning month
    7. getYear() - For returning year
    8. getTime() - For returning complete time

  6. #6
    Join Date
    Feb 2008
    Posts
    1,856

    Re: Create A Clock With Javascript

    You need to make use of the list below for javascript reference:
    • JavaScript Programmer's Reference
    • Teach Yourself JavaScript In A Week
    • Using JavaScript Special Edition
    • JavaScript For The World Wide Web 2
    • Instant JavaScript

    I always use JavaScript Programmer's Reference for my reference.

Similar Threads

  1. How to use javascript to create HTML and CSS
    By KennedII in forum Software Development
    Replies: 5
    Last Post: 22-02-2010, 11:10 PM
  2. Create calculator with the use of JavaScript
    By Jagdish Gada in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 09:00 AM
  3. JavaScript - How to create Element
    By Xylina in forum Software Development
    Replies: 3
    Last Post: 04-06-2009, 05:06 PM
  4. How to create analog clock using Small Basic
    By EricTheRed in forum Guides & Tutorials
    Replies: 3
    Last Post: 21-04-2009, 06:34 PM
  5. Create php alert pop ups using javascript.
    By Suzane in forum Software Development
    Replies: 3
    Last Post: 13-04-2009, 03:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •