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."