php中微妙函数,时间换算,秒、毫秒、微妙

1秒=1000毫秒(ms), 1毫秒=1/1000秒(s);

1秒=1000000 微秒(μs), 1微秒=1/1000000秒(s);

1秒=1000000000 纳秒(ns),1纳秒=1/1000000000秒(s);

1秒=1000000000000皮秒 1皮秒==1/1000000000000秒。

---------------------------------------------------

php 中微秒的函数是 microtime();

echo

microtime();

?>

结果: 0.76564300 1344219687

传递参数结果不变

echo microtime(ture);

?>

结果: 1344219687.7656

-------------------------------------------------------------------------------------

例子:

//在脚本中设置最好,这样就不怕程序在空间中使用,避免php.ini文件不能设置的烦恼

date_default_timezone_set("PRC");

//计算脚本运行的时间

class Timer {

private $startTime;

private $stopTime;

function __construct(){

$this->startTime=0;

$this->stopTime=0;

}

function start(){

$this->startTime=microtime(true);

echo

$this->startTime."
";

}

function stop(){

$this->stopTime=microtime(true);

echo

$this->stopTime."
";

}

function spent(){

//四舍五入,保留4位小数

return

round(($this->stopTime-$this->startTime),

4);

}

}

$timer=new Timer;

$timer->start();

for($i=0; $i<10000; $i++)

{

}

$timer->stop();

echo $timer->spent();