note 48138 added to function.time
| From: | jtacon@php.net | Date: | Mon, 13 Dec 2004 16:36:38 +0000 |
| Subject: | note 48138 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81753@lists.php.net to get a copy of this message | ||
Another function to convert seconds to human readable string:
function secsToText($time = 0) {
$hours = (int)floor($time/3600);
$minutes = (int)floor($time/60)%60;
$seconds = (int)$time%60;
if($hours==1) $txt = "$hours hour";
else if($hours>1) $txt = "$hours hours";
if($txt and $minutes>0 and $seconds>0) $txt .= ", ";
else if($txt and $minutes>0 and $seconds==0) $txt .= " and ";
$s = ($minutes>1) ? "s" : NULL;
if($minutes>0) $txt .= "$minutes minute$s";
$s = ($seconds>1) ? "s" : NULL;
if($txt and $seconds>0) $txt .= " and ";
if($seconds>0) $txt .= "$seconds second$s";
else if(!$txt and $seconds==0) $txt = "0 seconds";
return $txt;
}
print secsToText(86399); // Returns '23 hours, 59 minutes and 59 seconds'
print secsToText(86400); // Returns '24 hours'
print secsToText(86401); // Returns '24 hours and 1 second'
HTH.
Javier Tacón.
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48138
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48138&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48138&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48138&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48138&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48138&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48138&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48138&report=yes
Search -- http://master.php.net/manage/user-notes.php