PHP method for obtaining timestamp in milliseconds

Source: Internet
Author: User
This article describes how to obtain a timestamp in milliseconds in PHP. It involves php's processing skills for the results returned by the microtime function. It is very simple and practical. For more information, see

This article describes how to obtain a timestamp in milliseconds in PHP. It involves php's processing skills for the results returned by the microtime function. It is very simple and practical. For more information, see

This example describes how to obtain a timestamp in milliseconds in PHP. Share it with you for your reference. The specific analysis is as follows:

PHP does not provide a function for obtaining timestamp in milliseconds. You can use gettime () in java to obtain the timestamp. If you want to perform high-precision millisecond-level communication with some programs written in java, you need to use PHP to output millisecond-level time. Previously, I used an inaccurate method, that is, adding a three digit after the native time function of PHP. You can use the following code to obtain a more accurate timestamp in milliseconds:

<? Phpfunction getMillisecond () {list ($ t1, $ t2) = explode ('', microtime (); return (float) sprintf ('%. 0f', (floatval ($ t1) + floatval ($ t2) * 1000);} echo getMillisecond ();

I hope this article will help you with php programming.

,

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.