This article describes the PHP countdown to a 0-case solution. Share to everyone for your reference, specific as follows:
question: Today has the feedback, said the countdown has appeared-0 days situation, I looked at the procedure, the horizontal trough, at that time how did not test to
The reason is PHP's logical judgment -0 > 0
Analysis: post-error code
$starttime = 1362585600;//3.7 early
$nowtime = 1362618921;//3.7 morning
$off = ceil ($starttime-$nowtime)/ 86400); Countdown
if ($off < 0) {
$off = 0;
}
$b = $starttime-$nowtime;
$c = $b/86400;
$d = Ceil ($c);
Var_dump (Array (' Start-now ' => $b), Array (' Float_day ' => $c), Array (' Int_day ' => $d), array (' off ' => $off));
if ( -0 < 0) {
echo '-0 < 0 ';
} else {
echo '-0 > 0 ';
}
Output:
Array
' Start-now ' => int-33321
array
' float_day ' => float-0.385659722222
array
' int _day ' => float-0
array
' off ' => float-0
-0 > 0
Process:
When the start time is the same day as the current time, the above calculation process is -0 > 0, so the case of off =-0 occurs
Improved:
$starttime = 1362585600;//3.7 early
$nowtime = 1362618921;//3.7 Morning
if (($starttime-$nowtime) < 0) {
$off = 0;
} else {
$off = ceil (($starttime-$nowtime)/86400);
PS: This site also provides a UNIX timestamp conversion tool, very practical, to provide you with reference to:
Unix timestamp (timestamp) conversion tool:
Http://tools.jb51.net/code/unixtime
More about PHP Interested readers can view the site topics: "PHP date and Time usage summary", "PHP Mathematical Calculation Skills Summary", "PHP Array" operation Skills Encyclopedia, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Regular Expression Usage summary, "Summary of PHP operations and operator usage", "PHP string (String) Usage summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.