SimplePie_Misc::time_hms PHP Method

time_hms() public method

public time_hms ( $seconds )
    function time_hms($seconds)
    {
        $time = '';
        $hours = floor($seconds / 3600);
        $remainder = $seconds % 3600;
        if ($hours > 0) {
            $time .= $hours . ':';
        }
        $minutes = floor($remainder / 60);
        $seconds = $remainder % 60;
        if ($minutes < 10 && $hours > 0) {
            $minutes = '0' . $minutes;
        }
        if ($seconds < 10) {
            $seconds = '0' . $seconds;
        }
        $time .= $minutes . ':';
        $time .= $seconds;
        return $time;
    }

Usage Example

Example #1
0
 function get_duration($convert = false)
 {
     if ($this->duration !== null) {
         if ($convert) {
             $time = SimplePie_Misc::time_hms($this->duration);
             return $time;
         } else {
             return $this->duration;
         }
     } else {
         return null;
     }
 }