RE: [PHP] convert seconds to hours, minutes, seconds

From: Date: Tue, 03 Jun 2003 12:57:25 +0000
Subject: RE: [PHP] convert seconds to hours, minutes, seconds
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-149950@lists.php.net to get a copy of this message
Hi Chinmoy, > I have a value 178607, which is stored as seconds. I > like to convert it (178607 Secs) to Hours, Minutes and > Seconds appropiatly. Can anybody help me supplying the code? Try something like this: <?php function sec2hms ($secs) { $hms = ""; $hours = intval(intval($secs) / 3600); $hms .= $hours. ":"; $minutes = intval(($secs / 60) % 60); $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ":"; $seconds = intval($secs % 60); $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT); return $hms; } echo sec2hms(6). "<br>"; echo sec2hms(60). "<br>"; echo sec2hms(66). "<br>"; echo sec2hms(3600). "<br>"; echo sec2hms(3666). "<br>"; echo sec2hms(178607); ?> HTH Jon

« previous php.general (#149950) next »