我想停止我的php倒计时器停在00:00:00:00
这是我的代码
$due_date = strtotime('July 4, 2014 10:33 PM');
$rem = $due_date - time();
$day = floor($rem / 86400);
$hr = floor(($rem % 86400) / 3600);
$min = floor(($rem % 3600) / 60);
$sec = ($rem % 60);
echo "$day Days $hr Hours $min Minutes $sec Seconds Remaining...";
但是它会进一步延伸到-1,依此类推,在负值中。
我不想要它,我想在0处停止它。因此,当它停在零时,我可以回复我的任何消息。 任何想法怎么做?
提前多多感谢。答案 0 :(得分:0)
$due_date = strtotime('July 4, 2014 00:33 PM');
if($due_date > time()) {
$rem = $due_date - time();
$day = floor($rem / 86400);
$hr = floor(($rem % 86400) / 3600);
$min = floor(($rem % 3600) / 60);
$sec = ($rem % 60);
echo "$day Days $hr Hours $min Minutes $sec Seconds Remaining..."; // Timer still has time to go.
} else {
echo "0 Days 0 Hours 0 Minutes 0 Seconds Remaining..."; // Timer is finished, now at 00:00:00
}
答案 1 :(得分:0)
这一行
$rem = $due_date - time();
如果超过截止日期,将为零或负数。所以添加如下内容:
if($rem <= 0) {
//do your echo here for 00:00:00
}
else {
// do your countdown math as normal
}