Home  >  Article  >  php教程  >  PHP获得毫秒的时间microtime()用法

PHP获得毫秒的时间microtime()用法

WBOY
WBOYOriginal
2016-06-13 09:48:101055browse

在php中如果我们要获取毫秒就必须通过microtime()再进行转换,下面我来给各位朋友举几个实例,希望对大家会有所帮助。

问题不怕弱智…啥都记

 代码如下 复制代码

function getmicrotime() 

    list($usec, $sec) = explode(" ",microtime()); 
    return ((float)$usec + (float)$sec); 
}

其实就是处理了一下microtime()这个函数。

microtime()这个函数的返回值是这种形式:

0.06261400 1303715872

空格后面为当前的时间戳,空格前面是当前的精确时间

例,计算页面执行时间函数

 代码如下 复制代码

/**
* Simple function to replicate PHP 5 behaviour
*/
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

$time_start = microtime_float();

// Sleep for a while
usleep(100);

$time_end = microtime_float();
$time = $time_end - $time_start;

echo "Did nothing in $time secondsn";
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn