Kription wrote:
what I need is a way to take the 303 seconds and convert it to a human
readable:
0 hours 5 minutes and 3 seconds
Well, I wrote this yesterday. Does the job, but I'd be very interested
to hear what people think about efficiency and processor cost. Is a
funciton like this wildly unreasonable?
// timePassed is a function to turn a time into a more human-friendly format
// Provide it with the number of seconds that have passed, and it will
return a more suitable
// description of how much time has passed.
function timePassed($pastTimestamp)
{
$currentTimestamp = time();
$timePassed = $currentTimestamp - $pastTimestamp; //time passed in seconds
// Minute == 60 seconds
// Hour == 3600 seconds
// Day == 86400
// Week == 604800
$elapsedString = "";
if($timePassed > 604800)
{
$weeks = floor($timePassed / 604800);
$timePassed -= $weeks * 604800;
$elapsedString = $weeks." weeks, ";
}
if($timePassed > 86400)
{
$days = floor($timePassed / 86400);
$timePassed -= $days * 86400;
$elapsedString .= $days." days, ";
}
if($timePassed > 3600)
{
$hours = floor($timePassed / 3600);
$timePassed -= $hours * 3600;
$elapsedString .= $hours." hours, ";
}
if($timePassed > 60)
{
$minutes = floor($timePassed / 60);
$timePassed -= $minutes * 60;
$elapsedString .= $minutes." minutes, ";
}
$elapsedString .= $timePassed." seconds";
return $elapsedString;
}
If you think it's what you're looking for, feel free to use it.
--
Bob
London, UK
echo Mail fefsensmrrjyaheeoceoq\! | tr "jefroq\!" "@obe.uk"