This paper mainly introduces the implementation of PHP and time difference calculation method, involving PHP date and time conversion, operation and other related operational skills, the need for friends can refer to, hope to help everyone.
Example 1:
<?php//php Time comparison and difference calculation://(1). Compare the size of the two absolute time header ("content-type:text/html; Charset=utf-8 ");d ate_default_timezone_set (' PRC '), $zero 1=date (" y-m-d h:i:s ");//$zero 1 =" 2010-11-29 21:07:00 "; zero2= "2010-11-29 21:07:00", echo "Zero1 time:". $zero 1. " <br> "; echo" Zero2 time: ". $zero 2." <br> ";//strtotime-The datetime description of any English text to the Unix timestamp if (Strtotime ($zero 1) <strtotime ($zero 2) {echo" Zero1 earlier than Zero2 ";} else if (Strtotime ($zero 1) >strtotime ($zero 2)) {echo "Zero2 earlier than Zero1";} else{echo "Zero2 equals Zero1";} echo "<br/><br/>";? >
Operation Result:
Zero1 time: 2017-07-24 12:18:39zero2 time: 2010-11-29 21:07:00zero2 earlier than Zero1
Example 2:
<?php//(2). Countdown applet $zero1=strtotime (Date ("y-m-d h:i:s")); The current time, note h is 24 hours h is 12 hours $zero2=strtotime ("2018-1-1 00:00:00"); Chinese New Year//float ceil (float $value)//Returns the next integer not less than value, value if there is a fractional part in a bit. $guonian =ceil (($zero 2-$zero 1)/86400); 60s*60min*24hecho "<strong> $guonian </strong> days from the New Year! "Echo" <br/><br/> ";?" >
Operation Result:
It's 161 days before the new year.
Example 3:
<?php//(3). PHP calculates two time difference method $startdate=date ("y-m-d h:i:s"); $enddate = "2017-7-30 18:00:00";//floor-de-rounding//float floor (float $value) Returns the nearest integer less than value, rounding out the fractional part. $date =floor ((Strtotime ($enddate)-strtotime ($startdate))/86400); $hour =floor ((Strtotime ($enddate)-strtotime ($ StartDate)%86400/3600); $minute =floor ((Strtotime ($enddate)-strtotime ($startdate))%86400/60); $second =floor (( Strtotime ($enddate)-strtotime ($startdate))%86400%60); echo "Now is the end time". $date. " Day ". $hour." Hours ". $minute." Minutes ". $second." Seconds "; echo" <br/><br/> ";?" >
Operation Result:
Now it's 6 days, 5 hours, 339 minutes, 56 seconds, from the end time.