/**
* 直播倒计时
* 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;
}
倒计时计算 时/分秒
最新推荐文章于 2022-07-21 15:42:00 发布