PHP start stop timer

I am trying to code a simple stopwatch using PHP. I have a start and a stop button, and the resulting time is shown on the page. (in hours, mins and seconds.)
Does PHP have a built in timer function that can be used.?
Are there any scripts already available.?
All suggestions are welcome.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

See (have a look at the comments for function which convert second into hour, minutes ...)

For your case a very simple script would look like:
if(!empty($_POST['stop'])) {
    // elapsed time in seconds
    $etime=time() - $_POST['starrtime'];
    echo "elapsed time $etime<br>";
<form method="post">
<input type="hidden" name="starttime" value="<?php echo !empty($_POST['start']) ? time() : $_POST['starttime']; ?>">
<input type="submit" name="start" value="start">
<input type="submit" name="stop" value="stop">
I hope the functions below may help you..

// Use:
////  Create a timer object.  At creation, Start time is recorded
// $t1 = new StopWatch();
// // When code or section of code is complete, stop the timer.
// $t1->Stop();
// // Display the Elapsed Time in seconds.  Defaults to 2 decimal places
// // or override the display by passing a parameter.
// $t1->getElapsedTime(4);
class StopWatch {
    var $starttime;
    var $endtime;
    // Method Start
    // Purpose: Start Timer.
    function Start() {
        $this->starttime = microtime();
           return true;
    // Constructor StopWatch.  
    // Purpose: Start Timer.
       function StopWatch() {
        return true;
    // Method Stop
    // Purpose: Stop Timing.
    function Stop() {
          $this->endtime = microtime();
        return true;
    // Method getElapsedTime
    // @decimals Number of decimals places to display
    // Returns string
    // Purpose: Display elapsed time in seconds to precision passed in optional parameter
       function getElapsedTime($decimals=2) {
        // $decimals will set the number of decimals you want for your milliseconds.
           // format start time
        $decimals = intval($decimals);
        if ($decimals > 8)
          $decimals = 8;
        if ($decimals < 0)
          $decimals = 0;
        $endtime = explode(" ", $this->endtime);
           $endtime = (float)$endtime[1] + (float)$endtime[0];
           $starttime = explode (" ", $this->starttime);
           $starttime = (float)$starttime[1] + (float)$starttime[0];
        return number_format($endtime - $starttime, $decimals);
       // Member Function: Stop_getElapsedTime
    // @decimals Number of decimals places to display
    // Returns string
    // Purpose: Stop the timer and Display elapsed time in seconds to precision  passed in optional parameter
   function Stop_getElapsedTime($decimals=2) {
     return $this->getElapsedTime($decimals);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.