How PHP obtains the number of milliseconds in the current time

Source: Internet
Author: User
Tags current time echo display

PHP itself does not provide a function that returns the number of milliseconds, but provides a microtime () function that makes it easy to define a function that returns a number of milliseconds

PHP itself does not provide a function that returns the number of milliseconds. But it provides a microtime () function that returns an array that contains two elements, one in seconds and one in milliseconds, which makes it easy to define a function that returns a number of milliseconds, such as the following code:  function Getmillisecond () {list ($s 1, $s 2) = explode (", microtime ());  return (float) sprintf ('%.0f ', (Floatval ($s 1) + floatval ($s 2)) * 1000); Note that in a 32-bit system, the maximum size of PHP int is much less than the number of milliseconds, so you cannot use the int type, and PHP does not have a long type, so you have to use floating-point numbers to represent it. Because floating-point numbers are used, if the precision settings are not correct, the results obtained with the echo display may be incorrect, and to see the correct output, the precision setting cannot be less than 13 bits.
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.