<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_31245"> <div class="blockcode"> <div id="code_kzz"><ol> <li> <li><?php<li>class runTime {<li>private $starTime;//开始时间<li>private $stopTime;//结束时间<li>private function getMicTime(){<li>$mictime=microtime();//获取时间戳和微秒数<li>list($usec,$sec)=explode(" ",$mictime);//把微秒数分割成数组并转换成变量处理<li>return (float)$usec (float)$sec;//把转换后的数据强制用浮点点来处理<li>}<li>public function star(){//获取开始时间<li>$this->starTime=$this->getMicTime();</li> <li>}</li> <li>public function stop(){//获取结束时间</li> <li>$this->stopTime=$this->getMicTime();</li> <li>}</li> <li>public function spent(){//计算程序持续时间</li> <li>return round($this->stopTime-$this->starTime)*1000;//获取毫秒数</li> <li>}</li> <li>}</li> <li>//举例</li> <li>$time=new runTime();</li> <li>$time->star();</li> <li>for ($i=1;$i<=1000;$i ){<li>echo("a");<li>}<li>$time->stop();</li> <li>echo $time->spent();</li> <li>?></li> </ol></div> <em onclick="copycode($('code_kzz'));">复制代码</em> </div> </td></tr></table> <div id="comment_31245" class="cm"> </div> <div id="post_rate_div_31245"></div> <br><br>