In PHP, if we want to get milliseconds, we must use microtime() to convert them. Let me give you some examples. I hope it will be helpful to everyone.
Questions are not afraid of the mentally retarded...memorize everything
The code is as follows
代码如下 |
复制代码 |
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
|
|
Copy code
|
function getmicrotime()
{
List($usec, $sec) = explode(" ",microtime());
Return ((float)$usec + (float)$sec);
}
In fact, it just dealt with the microtime() function.
The return value of the microtime() function is in this form:
代码如下 |
复制代码 |
/**
* 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";
?>
|
| 0.06261400 1303715872
The space after the space is the current timestamp, and the space before the space is the current precise time
Example, calculate page execution time function
The code is as follows
|
Copy code
/**
* 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";
?>
http://www.bkjia.com/PHPjc/633053.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633053.htmlTechArticleIn php, if we want to get milliseconds, we must convert them through microtime(). Let me tell you what Here are a few examples, I hope it will be helpful to everyone. The problem is not afraid of the mentally retarded...
|
|