PHP get Millisecond Time microtime () Usage

Source: Internet
Author: User

In php, if we want to get a millisecond, we have to use microtime () for conversion. Next I will give you some examples, hoping to help you.

Not afraid of mental retardation... Everything

The Code is as follows: Copy code

Function getmicrotime ()
{
List ($ usec, $ sec) = explode ("", microtime ());
Return (float) $ usec + (float) $ sec );
}

In fact, we have processed the microtime () function.

The Return Value of the microtime () function is in this form:

0.06261400 1303715872

The space is followed by the current timestamp, and the space is preceded by the current exact time

For example, calculate the page execution time function

The Code is as follows: Copy code

<? Php
/**
* Simple function to replicate PHP 5 behaviour
*/
Function microtime_float ()
{
List ($ usec, $ sec) = explode ("", microtime ());
Return (float) $ usec + (float) $ sec );
}

$ Time_start = microtime_float ();

// Sleep for a while
Usleep (100 );

$ Time_end = microtime_float ();
$ Time = $ time_end-$ time_start;

Echo "Did nothing in $ time secondsn ";
?>

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.