所以这就是我需要做的事情:
基本上,它会在下一集电视节目的播出时间倒计时并显示下一集节目号,这将持续到所有剧集播出。
这是我目前所拥有的,它在一定程度上有效,但只有+7天/ ++一集,之后倒计时将进入底片。我尝试过while循环和其他一些东西,但我没有太多运气。
$date = "February 12, 2013 5:06 PM";
$date = strtotime($date);
$remaining = $date - time();
$episode = 0;
if ($remaining < 0) {
++$episode;
$remaining = strtotime("+7 day", $date) -time();
}
$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);
$mins_remaining = floor(($remaining % 86400 % 3600) / 60);
if ($episode == 3){
echo "Aired";
} else {
echo "$days_remaining:$hours_remaining:$mins_remaining Ep $episode";
}
非常感谢任何建议,谢谢!
答案 0 :(得分:0)
当然会消极。
$remaining
达到0后,还会再添加7天。
if ($remaining < 0) { // remaining: less than 0 days
++$episode; // episode becomes 1
$remaining = strtotime("+7 day", $date) -time(); // remaining: less than 7 days
}
然而,在又过了7天后,$remaining
仍为负数,仅添加了7天。由于您尚未在数据库中保存$episode
,因此根据代码,它仍为0。
$episode = 0; // $episode starts at 0 according to the code
if ($remaining < 0) { // remaining: less than -7 days
++$episode; // episode becomes 1
因此,它会继续计算为负数,并为您提供$episode == 1
。
你应该这样做:
$date = strtotime("February 12, 2013 5:06 PM");
for ($i = 0; $i < 3; $i++) {
$episodes[$i+1] = strtotime("+". 7*$i ." day", $date);
$remainings[$i+1] = $episodes[$i+1] - time();
}
foreach ($remainings as $key => $remaining) {
if ($remaining > 0) {
$episode = $key;
$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);
$mins_remaining = floor(($remaining % 86400 % 3600) / 60);
break;
}
}
if (!isset($episode)){
echo "Aired";
} else {
echo "$days_remaining:$hours_remaining:$mins_remaining Ep $episode";
}