1.<?php 2. $zero 1=date ("y-m-d h:i:s"); 3. $zero 2 = "2010-11-29 21:07:00′; 4. Echo "Zero1 time:". $zero 1. " <br> "; 5. Echo "Zero2 time:". $zero 2. " <br> "; 6. if (Strtotime ($zero 1) <strtotime ($zero 2)) { 7. echo "Zero1 earlier than zero2′; 8.}else{ 9. echo "Zero2 earlier than zero1′; Ten.} ?>
Above is the size of the comparison two absolute time
<?php $zero 1=strtotime (Date ("y-m-d h:i:s"));//Current Time , note H is 24 h is 12 hours $zero 2=strtotime ("2014-1-21 00:00:00 "); Chinese New Year, can not write 2014-1-21 24:00:00 so not $guonian =ceil (($zero 2-$zero 1)/86400);//60s*60min*24h echo "< from New Year's Day strong> $guonian </strong> Days! "; ? >
Above is the Countdown applet instance code
<?php//PHP calculates two time-difference methods $startdate = "2010-12-11 11:40:00"; $enddate = "2012-12-12 11:45:09"; $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 $date. " Day <br> "Echo $hour." H <br> "; Echo $minute." Minutes <br> "Echo $second." SEC <br> ";? >
<?php
/**
* Time Difference calculation
*
* @param Timestamp $time
* @return String Time Elapsed
* @author Shelley Shyan
* @copyright http://phparch.cn (Professional PHP Architecture)
*/
function Time2units ($time)
{
$year = Floor ($time/60/60/24/365);
$time-= $year * 60 * 60 * 24 * 365;
$month = Floor ($time/60/60/24/30);
$time-= $month * 60 * 60 * 24 * 30;
$week = Floor ($time/60/60/24/7);
$time-= $week * 60 * 60 * 24 * 7;
$day = Floor ($time/60/60/24);
$time-= $day * 60 * 60 * 24;
$hour = Floor ($time/60/60);
$time-= $hour * 60 * 60;
$minute = Floor ($time/60);
$time-= $minute * 60;
$second = $time;
$elapse = ";
$UNITARR = Array (' Year ' = ' + ' Years ', ' month ' = ' ' month ', ' Week ' = ' ' Week ', ' Day ' = ' ~ ',
' Hours ' = ' hour ', ' minutes ' = ' minute ', ' sec ' = ' second '
);
foreach ($unitArr as $CN = $u)
{
if ($ $u > 0)
{
$elapse = $ $u. $CN;
Break
}
}
return $elapse;
}
$past = 2052345678; Some Timestamp in the past
$now = time (); Current timestamp
$diff = $now-$past;
Echo ' published in '. Time2units ($diff). ' former ';
?>
How to calculate the time comparison and difference between PHP