wxstatus file age

For those who use the wxstatus page like the one seen here: http://www.relayweather.com/wxstatus.php

I’ve found a function that will convert the file age in seconds to hours:minutes:seconds (00:00:00)
My status page used to display something like 589 secs. but now, it will display 0:09:49

Place this function in your status file:


<?php

function sec2hms ($sec, $padHours = false) {

    $hms = "";
    
    // there are 3600 seconds in an hour, so if we
    // divide total seconds by 3600 and throw away
    // the remainder, we've got the number of hours
    $hours = intval(intval($sec) / 3600); 

    // add to $hms, with a leading 0 if asked for
    $hms .= ($padHours) 
          ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
          : $hours. ':';
     
    // dividing the total seconds by 60 will give us
    // the number of minutes, but we're interested in 
    // minutes past the hour: to get that, we need to 
    // divide by 60 again and keep the remainder
    $minutes = intval(($sec / 60) % 60); 

    // then add to $hms (with a leading 0 if needed)
    $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';

    // seconds are simple - just divide the total
    // seconds by 60 and keep the remainder
    $seconds = intval($sec % 60); 

    // add to $hms, again with a leading 0 if needed
    $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);

    return $hms;
}
?> 

Replace where the script echo’s the age ($age) with the following:

<?php echo sec2hms($age); ?>

Michael

Nice Status page, looks very clean, is it available for downloading, or are you gonna make it available for others to use?
Been trying to make a page like yous but can’t get it to look as nice as yours.

Doug