note 48138 deleted from function.time by aidan

From: Date: Sat, 08 Oct 2005 01:04:20 +0000
Subject: note 48138 deleted from function.time by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96619@lists.php.net to get a copy of this message
Note Submitter: jtacon at php dot net ---- 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.

« previous php.notes (#96619) next »