PHP中时间比较

比较两个绝对时间的大小
  1. <?php   
  2.  $zero1=date(“y-m-d h:i:s”);   
  3.  $zero2=”2010-11-29 21:07:00′;   
  4.  echo “zero1的时间为:”.$zero1.”<br>”;   
  5.  echo “zero2的时间为:”.$zero2.”<br>”;   
  6.  if(strtotime($zero1)<strtotime($zero2)){   
  7.   echo “zero1早于zero2′;   
  8.  }else{   
  9.   echo “zero2早于zero1′;   
  10.  }   
  11.  ?>  
倒计时小程序 实例代码:  
Code   ViewCopyPrint
  1. <?php   
  2.  $zero1=strtotime (date(“y-m-d h:i:s”)); //当前时间   
  3.  $zero2=strtotime (“2011-2-03 24:00:00′);  //过年时间   
  4.  $guonian=ceil(($zero2-$zero1)/86400); //60s*60min*24h   
  5.  echo “离过年还有<strong>$guonian</strong>天!”;   
  6.  ?>  

posted on 2013-01-31 21:50  cnjack  阅读(146)  评论(0编辑  收藏  举报

导航