note 40377 added to function.time
| From: | nemmeh at hotmail dot com | Date: | Tue, 02 Mar 2004 00:07:41 +0000 |
| Subject: | note 40377 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-66067@lists.php.net to get a copy of this message | ||
Slightly improved...
<?php
function duration($t) {
$s = $t % 60;
$m = ($t /= 60) % 60;
$h = ($t /= 60) % 24;
$x = ($t /= 24) % 365;
$d = $x % 7;
$w = floor($x / 7);
$y = floor($t / 365);
$r = "$y years, $w weeks, $d days, $h hours, $m minutes, $s seconds";
$r = preg_replace('/0 \S+ /', "", $r);
$r = preg_replace('/, 0 \S+/', "", $r);
$r = preg_replace('/( 1 \S+)s/', "$1", $r);
$r = preg_replace('/,( \d+ \S+)$/', " and$1", $r);
return $r;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40377
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40377&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40377&report=yes
Search -- http://master.php.net/manage/user-notes.php