倒计时计算 时/分秒

/**
     * 直播倒计时
     * Created by PhpStorm.
     * User: EricPan
     * Date: 2020/4/2
     * Time: 10:41
     * @param Request $request
     * @return array
     */
    public function liveTime(Request $request)
    {
        $time = $this->getLiveTime();
        $dayTime = 60*60*24;
        $hourTime = 60*60;
        $branchTime = 60;
        // 剩余描述
        $surplus = strtotime($time)-time();
        $reTime = $surplus;
        $day = $this->surplus($surplus, $dayTime);
        $hour = $this->surplus($surplus, $hourTime);
        $branch = $this->surplus($surplus, $branchTime);

        return [
            'day' => (string)$day,
            'hour' => (string)$hour,
            'branch' => (string)$branch,
            'time' => $reTime
        ];
    }

    /**
     * 剩余时间计算
     * Created by PhpStorm.
     * User: EricPan
     * Date: 2020/4/2
     * Time: 10:39
     * @param $surplus
     * @param $time
     * @return float|int|string
     */
    private function surplus(&$surplus,$time)
    {
        $re = 0;
        if($surplus > $time)
        {
            $re = floor($surplus/$time);
            $surplus = $surplus-$re*$time;
        }

        $re = strlen($re) == 1?'0'.$re:$re;

        return $re;
    }
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读