note 74742 added to function.time
| From: | jason at thinkingman dot org | Date: | Wed, 25 Apr 2007 23:35:19 +0000 |
| Subject: | note 74742 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-125868@lists.php.net to get a copy of this message | ||
Ok -- because Weeks are important too, I've added them into the function.
<?php
// calc_tl (calculate time-lapse)
// Written by J.C.
// April 24th, 2007
//
// Usage:
// $tl = calc_tl($unixTimeStamp, [$unixStopTime], [viewScope])
//
// Returns an Array.
//
// License: Free to use, disect, add-to, remove-from, modify,
// convert or just play with. May not be used if you
// are an evil bad person.
function calc_tl($t, $sT = 0, $showMe = 'y') {
if((int)$sT) {
$t = ($sT - $t);
}
$r = array();
if($t > 0) {
$sY = 31536000;
$sW = 604800;
$sD = 86400;
$sH = 3600;
$sM = 60;
switch(strtolower($showMe)) {
case 'y':
$y = ((int)($t / $sY));
$t = ($t - ($y * $sY));
$r['string'] .= "{$y} years ";
$r['years'] = $y;
case 'w':
$w = ((int)($t / $sW));
$t = ($t - ($w * $sW));
$r['string'] .= "{$w} weeks ";
$r['weeks'] = $w;
case 'd':
$d = ((int)($t / $sD));
$t = ($t - ($d * $sD));
$r['string'] .= "{$d} days ";
$r['days'] = $d;
case 'h':
$h = ((int)($t / $sH));
$t = ($t - ($h * $sH));
$r['string'] .= "{$h} hours ";
$r['hours'] = $h;
case 'm':
$m = ((int)($t / $sM));
$t = ($t - ($m * $sM));
$r['string'] .= "{$m} minutes ";
$r['minutes'] = $m;
case 's':
$s = $t;
$r['string'] .= "{$s} seconds";
$r['seconds'] = $s;
break;
}
}
return $r;
}
?>
----
Server IP: 69.39.81.135
Probable Submitter: 71.128.119.221
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- https://master.php.net/note/edit/74742
Del: integrated -- https://master.php.net/note/delete/74742/integrated
Del: useless -- https://master.php.net/note/delete/74742/useless
Del: bad code -- https://master.php.net/note/delete/74742/bad+code
Del: spam -- https://master.php.net/note/delete/74742/spam
Del: non-english -- https://master.php.net/note/delete/74742/non-english
Del: in docs -- https://master.php.net/note/delete/74742/in+docs
Del: other reasons-- https://master.php.net/note/delete/74742
Reject -- https://master.php.net/note/reject/74742
Search -- https://master.php.net/manage/user-notes.php