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.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.