Use PHP time Date function strtotime () to implement a countdown function example

Source: Internet
Author: User
In the previous we used the Strtotime () function, which realized the function of comparing the size of two time, in addition to comparing the size of two dates, PHP can also accurately calculate the difference of two dates. In this chapter, we still use the Strtotime () function Develop a countdown feature.

The Strtotime () function is to parse the date and time of any English text into a Unix timestamp, which we have explained before, and do not introduce too much here, and we look directly at the code.

Countdown Applet Instance , the code is as follows

<?phpheader ("Content-type:text/html;charset=utf-8");    Set the encoding $time1=strtotime (date ("y-m-d h:i:s"));                              Gets the current time $time2=strtotime ("2017-5-1");                              51 Holiday Time $time3=strtotime ("2017-5-5");                              Dragon Boat Festival Holiday Time $sub1=ceil (($time 2-$time 1)/3600);                            (60 seconds *60 minutes) seconds per hour $sub2=ceil (($time 3-$time 1)/86400);                           (60 seconds *60 minutes * 24 hours) seconds/day echo "51 off time and". " ". $sub 1." "." Hours!!! "echo" <p> "echo" from the Dragon Boat Festival holiday Time and "." ". $sub 2." "." Days!!! ";? >

Code Run Result:

In the example above we used the ceil () function, and here we look at the ceil () function

The ceil () function: is rounded to the nearest integer. The syntax format is as follows:

Ceil (x)

Description

Returns the next integer not less than x, or x if there are fractional parts. The type returned by Ceil () is still float, because the range of float values is usually larger than the integer.

See an example of a ceil () function

<?phpecho ceil (0.60). " <br/> "Echo   ceil (5.1);? >

Ceil () function instance run Result:

In the next section, we'll show you how to "calculate the run time of a page script."

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.