Solved

Special clock...?

Posted on 2003-11-09
2
236 Views
Last Modified: 2008-03-06
Can I make a clock that starts off the same as the server time, but then runs twice as fast as a clock in reality? Also it would have to print the data onto a page.
0
Comment
Question by:JavaHead_Jonnie
2 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 150 total points
ID: 9712106
sure why not,

<html>
<head>
<script type="text/javascript">
var timer = null

<?PHP
$now=getdate();
echo "var hours = ".$now['hours']."\n";
echo "var minutes = ".$now['minutes']."\n";
echo "var seconds = ".$now['seconds']."\n";
?>
function start_clock()
{
timer = setTimeout("update_clock()",1000)
}

function stop_clock()
{
clearTimeout(timer)
}

function update_clock()
{
  if (seconds < 59)
    seconds++
  else
  {
    seconds=0
    if (minutes < 59)
       minutes++
    else
    {
      minutes=0
      if (hours < 12)
        hours++
      else
        hours=1
    }
  }
document.forms["clock"].display.value = hours + ":" + ((minutes < 10) ? "0" : "") + minutes + ":" + ((seconds < 10) ? "0" : "") + seconds
timer = setTimeout("update_clock()",1000) //********* change this to 500 to make the clock run twice as fast
}
</script>
</head>
<body onload="start_clock()" onunload="stop_clock()">
<form name="clock">
<input type="text" name="display" size="10">
</form>
</body>
</html>
0
 

Author Comment

by:JavaHead_Jonnie
ID: 9715825
Thanks, it works a treat! It's just what I wanted.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now