1k views

Convert Seconds To "Hours Minutes Seconds" Words

PHP
  1. <?php
  2.  
  3. /**
  4.  *
  5.  * @convert seconds to hours minutes and seconds
  6.  *
  7.  * @param int $seconds The number of seconds
  8.  *
  9.  * @return string
  10.  *
  11.  */
  12.  
  13. function secondsToWords($seconds)
  14. {
  15.     /*** return value ***/
  16.     $ret = "";
  17.  
  18.     /*** get the hours ***/
  19.     $hours = intval(intval($seconds) / 3600);
  20.     if($hours > 0)
  21.     {
  22.         $ret .= "$hours hours ";
  23.     }
  24.     /*** get the minutes ***/
  25.     $minutes = bcmod((intval($seconds) / 60),60);
  26.     if($hours > 0 || $minutes > 0)
  27.     {
  28.         $ret .= "$minutes minutes ";
  29.     }
  30.  
  31.     /*** get the seconds ***/
  32.     $seconds = bcmod(intval($seconds),60);
  33.     $ret .= "$seconds seconds";
  34.  
  35.     return $ret;
  36. }
  37. ?>
  38.  

­

Tags: PHP date/time

Embed: