Home > Backend Development > PHP Tutorial > How to get the milliseconds of the current time in php_PHP tutorial

How to get the milliseconds of the current time in php_PHP tutorial

WBOY
Release: 2016-07-13 10:39:49
Original
1259 people have browsed it

PHP itself does not provide a function that returns the number of milliseconds, but it provides a microtime() function, which returns an array containing two elements, one is the number of seconds and the other is the number of milliseconds expressed as a decimal. With the help of this function, you can easily Define a function that returns milliseconds, for example:

Copy code The code is as follows:

function getMillisecond() {
list($s1, $s2) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($s1) + floatval($s2)) * 1000) ;
}

It should be noted that in 32-bit systems, the maximum int value of php is far less than the number of milliseconds, so the int type cannot be used, and there is no long type in php, so you have to use float expressed in points. Due to the use of floating point numbers, if the precision setting is incorrect, the obtained results may not be displayed correctly when using echo. To see the correct output, the precision setting cannot be lower than 13 digits.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/728113.htmlTechArticlephp itself does not provide a function that returns the number of milliseconds, but it provides a microtime() function, which returns an array , contains two elements, one is the number of seconds, the other is the millisecond expressed as a decimal...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template