<script>
   function getClock() {
      document.title= updateClock(); // make a call to the updateClock() function to return the current time value
   }

   // this function uses settimeout function
   function updateClock() {
      var now = new Date();
      var clock = setTimeout("getClock()", 1000); //update getClock() function
      //////////////////////////////////////////
      clock = now.getMonth()+1 + "/" + now.getDate() + "/" + now.getYear() + "-" + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
      //////////////////////////////////////////
      return clock;
   }
   // this is more like an endless loop where two functions call each other
</script>

<!---------------------------------------------------------------------->
<body onLoad="getClock()">
   <h2>
      Watch the title on your page. See time slip out of your hands !
   </h2>

About This Tutorial
Author: Anang A Phatak
Skill Level: Beginner 
 
 
 
Platforms Tested: CFMX
Total Views: 31,465
Submission Date: January 05, 2005
Last Update Date: June 05, 2009
All Tutorials By This Autor: 12
Discuss This Tutorial
  • I'm trying to create a page where I can click button to start a timer and then stop to stop the timer... I want the page to refresh and display the duration of the event. You can't do this with datediff or any of the other functions I've found. Do I have to do the date and then the time?

  • Here is a redirection script. Hope this is of value to some...

  • Here is a redirection script. Hope this is of value to some...

  • To get this clock to show in the body of your page; function getClock() { clock.value = updateClock(); // make a call to the updateClock() function to return the current time value } // this function uses settimeout function function updateClock() { var now = new Date(); var clock = setTimeout("getClock()", 1000); //update getClock() function clock = now.getMonth()+1 + "/" + now.getDate() + "/" + now.getYear() + "-" + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds(); return clock; }

Advertisement

Sponsored By...
Powered By...