PHP microtime function
The PHP microtime function can be used to read the current Unix timestamp of the server and the number of microseconds. The time or mktime function of PHP can only return to seconds , while the microtime function can return to milliseconds below the decimal point. For example, time can return 1415335769. Microtime can return 1415335769.36 such a Unix timestamp. In other words, microtime is more accurate than the time function, but microtime can only be used in an operating system environment that supports the gettimeofday() system call.
Basic syntax of PHP microtime function
In the traditional case, to obtain a result like 1415335769.37, it must be processed by other functions such as explode. It is really a bit troublesome, until the PHP 5.4.0 version began to add the get_as_float parameter, if the get_as_float parameter is set to true, microtime will return a The Unix timestamp with two decimal places can easily get the result we want, that is, directly output the result "1415335769.37". The actual operation of this part will be clearly presented to you in the example.
PHP microtime function application example
echo'<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; //Web page encoding declaration
echo'Current Unix timestamp seconds:'. time( ).'Seconds<br>';
echo'Result of PHP microtime:'.microtime().'<br>';
echo'Current Unix timestamp seconds:'.microtime(true).'second';
?>
PHP microtime result: 0.01306500 1415337041
Current Unix timestamp seconds: 1415337041.01 seconds
Supplement, let microtime use the true parameter to output the result with rounding function.
Post a Comment
0 Comments