首页 > 编程知识 正文

php毫秒转换时分秒,php date 毫秒

时间:2023-05-05 18:24:43 阅读:213803 作者:2748

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();

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。