public static function secondsToText($seconds, $returnAsWords = false)
    {
        $periods = [
            'year'   => 3.156e+7,
            'month'  => 2.63e+6,
            'week'   => 604800,
            'day'    => 86400,
            'hour'   => 3600,
            'minute' => 60,
            'second' => 1,
        ];

        $parts = [];
        foreach ($periods as $name => $dur) {
            $div = floor($seconds / $dur);

            if ($div == 0) {
                continue;
            }

            if ($div == 1) {
                $parts[] = ($returnAsWords ? self::numberToWord($div) : $div).' '.$name;
            } else {
                $parts[] = ($returnAsWords ? self::numberToWord($div) : $div).' '.$name.'s';
            }

            $seconds %= $dur;
        }

        $last = array_pop($parts);

        if (empty($parts)) {
            return $last;
        }

        return implode(', ', $parts).' and '.$last;
    }
public static function secondsToText($seconds, $returnAsWords = false)
    {
        $periods = [
            'year'   => 3.156e+7,
            'month'  => 2.63e+6,
            'week'   => 604800,
            'day'    => 86400,
            'hour'   => 3600,
            'minute' => 60,
            'second' => 1,
        ];

        $parts = [];
        foreach ($periods as $name => $dur) {
            $div = floor($seconds / $dur);

            if ($div == 0) {
                continue;
            }

            if ($div == 1) {
                $parts[] = ($returnAsWords ? self::numberToWord($div) : $div).' '.$name;
            } else {
                $parts[] = ($returnAsWords ? self::numberToWord($div) : $div).' '.$name.'s';
            }

            $seconds %= $dur;
        }

        $last = array_pop($parts);

        if (empty($parts)) {
            return $last;
        }

        return implode(', ', $parts).' and '.$last;
    }
public static function secondsToText ( $ seconds , $ returnAsWords = false ) { $ periods = [ 'year' => 3.156e+7 , 'month' => 2.63e+6 , 'week' => 604800 , 'day' => 86400 , 'hour' => 3600 , 'minute' => 60 , 'second' => 1 , ] ; $ parts = [ ] ; foreach ( $ periods as $ name => $ dur ) { $ div = floor ( $ seconds / $ dur ) ; if ( $ div == 0 ) { continue ; } if ( $ div == 1 ) { $ parts [ ] = ( $ returnAsWords ? self :: numberToWord ( $ div ) : $ div ) . ' ' . $ name ; } else { $ parts [ ] = ( $ returnAsWords ? self :: numberToWord ( $ div ) : $ div ) . ' ' . $ name . 's' ; } $ seconds %= $ dur ; } $ last = array_pop ( $ parts ) ; if ( empty ( $ parts ) ) { return $ last ; } return implode ( ', ' , $ parts ) . ' and ' . $ last ; }
Convert seconds to real time.

@param int  $seconds       time in seconds
@param bool $returnAsWords return time in words (example one minute and 20 seconds) if value is True or (1 minute and 20 seconds) if value is false, default false

@return string
Convert seconds to real time .