php专区

 首页 > php专区 > PHP高级 > 日期 > php 代码运行时间查看类 - php日期

php 代码运行时间查看类 - php日期

分享到:
【字体:
导读:
          classRunTime 页面执行时间类{private$starttime; 页面开始执行时间private$stoptime; 页面结束执行时间private$spendtime; 页面执行花费时间functiongetmicrotime() 获取返回当前微秒数的浮...

php 代码运行时间查看类

  1. class RunTime//页面执行时间类  
  2. {  
  3.  private $starttime;//页面开始执行时间  
  4.  private $stoptime;//页面结束执行时间  
  5.  private $spendtime;//页面执行花费时间  
  6.  function getmicrotime()//获取返回当前微秒数的浮点数  
  7.  {  
  8.   list($usec,$sec)=explode(" ",microtime());  
  9.   return ((float)$usec + (float)$sec);  
  10.  }  
  11.  function start()//页面开始执行函数,返回开始页面执行的时间  
  12.  {  
  13.   $this->starttime=$this->getmicrotime();  
  14.  }  
  15.  function end()//显示页面执行的时间  
  16.  {  
  17.   $this->stoptime=$this->getmicrotime();  
  18.   $this->spendtime=$this->stoptime-$this->starttime;  
  19.   //return round($this->spendtime,10);  
  20.  }  
  21.  function display() 
  22.  { 
  23.      //$this->end(); 
  24.      echo "

    运行时间:".round($this->spendtime,10)."秒

    "
  25.  } 
  26. }  
  27. /*调用方法    
  28. $timer=new Runtime();  
  29. $timer->start();  
  30.  
  31. $timer->end(); 
  32. $timer->display(); 
分享到:
php显示文章 几分钟前,几小时前,几天前发...
php显示文章 几分钟前,几小时前,几天前发布类 文章发表时的UNIX时间戳,来转化为例如,几分钟前,几小时前,几天前....这样的提示,如微博,这看起来更加人性化,类代码如下:
php 时间数据转换为时间戳代码 - php日期
php 时间数据转换为时间戳代码 要做时间数据转换为时间戳我们利用php教程自带函数,strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳. 格式一 Fri Aug 05 12:19:04 +0800 2011 strtotime("Fri Aug 05 12:19:04 +0800 2011"); 格式二 2011-02-01 strtotime("2011-02-01"); ...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……