美文网首页
php 自动把秒转换成分或者时

php 自动把秒转换成分或者时

作者: Renew全栈工程师 | 来源:发表于2019-12-31 22:23 被阅读0次
    /**
     * 格式化秒自动到 分或者时
     * @param int $second
     * @return string
     */
    function formatSecond($second = 0)
    {
        $unit = 0;

        $result = $second;

        $unitString = ['秒', '分', '时'];

        while ($result > 59 && $unit < count($unitString) - 1) {
            $unit++;

            $result = floor($result / 60);
        }

        return $result . $unitString[$unit];
    }

相关文章

网友评论

      本文标题:php 自动把秒转换成分或者时

      本文链接:https://www.haomeiwen.com/subject/rxgioctx.html