note 43656 added to function.time
| From: | NOSPAMPLEASEgareth_AT_ignitedDOTcoDOTuk at rn2 dot php dot net | Date: | Tue, 29 Jun 2004 11:34:56 +0000 |
| Subject: | note 43656 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72108@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43656
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43656&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43656&report=yes
Search -- http://master.php.net/manage/user-notes.php