note 43656 deleted from function.time by nlopess

From: Date: Tue, 29 Jun 2004 11:39:49 +0000
Subject: note 43656 deleted from function.time by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72109@lists.php.net to get a copy of this message
Note Submitter: NOSPAMPLEASEgareth_AT_ignitedDOTcoDOTuk ---- I've wrote a nicer format elapsed seconds function that someone may find useful. <? echo formatSeconds(130, "%d Day(s) %h Hour(s) %m Minute(s) %s Second(s)"); // Output : 0 Day(s) 0 Hour(s) 2 Minute(s) 10 Second(s) function formatSeconds($seconds, $format) { $secondsPerDay = 86400; $secondsPerHour = 3600; $secondsPerMinute = 60; $d = floor($seconds / $secondsPerDay); $h = floor(($seconds % $secondsPerDay) / $secondsPerHour); $m = floor((($seconds % $secondsPerDay) % $secondsPerHour) / $secondsPerMinute); $s = floor((($seconds % $secondsPerDay) % $secondsPerHour) % $secondsPerMinute); $format = str_replace("%d", $d, $format); $format = str_replace("%D", sprintf("%02d", $d), $format); $format = str_replace("%h", $h, $format); $format = str_replace("%H", sprintf("%02d", $h), $format); $format = str_replace("%m", $m, $format); $format = str_replace("%M", sprintf("%02d", $m), $format); $format = str_replace("%s", $s, $format); $format = str_replace("%S", sprintf("%02d", $s), $format); return $format; } ?>

« previous php.notes (#72109) next »