<?php error_reporting(E_ALL); class RunTime{ private $startTime=''; private $endTime=''; function __construct() { $this->startTime = $this->getMicroTimeAsFloat(); } function getMicroTimeAsFloat(){ list($fractionalSeconds,$seconds)=explode(" ", microtime()); return ((float)$seconds + (float)$fractionalSeconds); } function elapsed(){ $this->endTime = $this->getMicroTimeAsFloat(); return ($this->endTime - $this->startTime); } } 運行方式:引入該類,在頁面頭部初始化,$rt= new Runtime(); 頁面底部顯示 echo $rt->elapsed();