PHP 根据时间戳计算时分秒

/**
     * 计算时分秒
     * @desc (计算时分秒)
     * @return array
     * @api (int ,time,时间戳,)
     */
    public function format_time($time, $sign = 0)
    {
        $h = $m = $s = 0;
        $str = "";
        $s = floor($time % 60);
        $m = floor($time / 60) % 60;
        $h = floor($time / 60 / 60);
        if( $sign == 0 )
        {
            if( 0 < $h )
            {
                return $str = $h . "时" . $m . "分" . $s . "秒";
            }

            if( 0 < $m )
            {
                return $str = $m . "分" . $s . "秒";
            }

            return $str = $s . "秒";
            }

            if( $sign == 1 )
            {
                if( $m < 10 )
                {
                    $m = "0" . $m;
                }

                if( $s < 10 )
                {
                    $s = "0" . $s;
                }

                if( 0 < $h )
                {
                    return $str = $h . ":" . $m . ":" . $s;
                }

                if( 0 < $m )
                {
                    return $str = $m . ":" . $s;
                }

                return $str = "00:" . $s;
            }

        return NULL;
    }

你可能感兴趣的:(ThinkPHP,php,android,java)