In php, if we want to get a millisecond, we have to use microtime () for conversion. Next I will give you some examples, hoping to help you.
Not afraid of mental retardation... Everything
| The Code is as follows: |
Copy code |
|
Function getmicrotime ()
{
List ($ usec, $ sec) = explode ("", microtime ());
Return (float) $ usec + (float) $ sec );
} |
In fact, we have processed the microtime () function.
The Return Value of the microtime () function is in this form:
0.06261400 1303715872
The space is followed by the current timestamp, and the space is preceded by the current exact time
For example, calculate the page execution time function
| The Code is as follows: |
Copy code |
|
<? Php
/**
* 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 ";
?> |