note 35898 added to function.time
| From: | jcarroll at rn2 dot php dot net | Date: | Thu, 18 Sep 2003 15:58:55 +0000 |
| Subject: | note 35898 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-56707@lists.php.net to get a copy of this message | ||
To calculate an elapsed time, I would suggest using _floor rather than _round (as per prev user
note). _round will produce incorrect results. Try instead:
function calcElapsedTime($time)
{
// calculate elapsed time (in seconds!)
$diff = time()-$time;
$daysDiff = floor($diff/60/60/24);
$diff -= $daysDiff*60*60*24;
$hrsDiff = floor($diff/60/60);
$diff -= $hrsDiff*60*60;
$minsDiff = floor($diff/60);
$diff -= $minsDiff*60;
$secsDiff = $diff;
return ('(elapsed time '.$daysDiff.'d '.$hrsDiff.'h
'.$minsDiff.'m '.$secsDiff.'s)');
}
[NOTE: I converted this from a javascript function originally posted in http://developer.irt.org/script/217.htm ... note
that cited function does not appear to work with versions of Javascript after 1.3.x ...]
Sample call would be:
echo calcElapsedTime(filectime('somefile.txt'));
Output would resemble:
(elapsed time 0d 1h 12m 2s)
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35898
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35898&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35898&report=yes