Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Special clock...?

Posted on 2003-11-09
2
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
Michael701 earned 600 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

597 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