note 35898 deleted from function.time by aidan

From: Date: Sat, 08 Oct 2005 01:06:48 +0000
Subject: note 35898 deleted from function.time by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96638@lists.php.net to get a copy of this message
Note Submitter: jcarroll at nospam theworld dot com ---- 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)

« previous php.notes (#96638) next »