/**
* 倒计时
* 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;
}
PHP 倒计时计算
最新推荐文章于 2022-11-15 10:42:16 发布