PHP Countdown Appearance-0 Solution _php Tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.