PHP retrieves the current time in milliseconds

Source: Internet
Author: User
Tags time in milliseconds
1second1000millisecond1000, 000microsecond1000, 000,000 nanosecondphp has no default function in milliseconds, but a microtime () function is provided. the function returns two elements, one of which is the number of seconds, one is the number of milliseconds represented by decimals. with this function, you can easily define a function that returns the number of milliseconds, for example :*... 1 second = 1000 millisecond = 1000,000 microsecond = 1000,000,000 nanosecond

Php does not have a default function in milliseconds, but a microtime () function is provided. the function returns two elements, one being the number of seconds and the other being the number of milliseconds represented by decimals, with this function, you can easily define a function that returns the number of milliseconds, for example:

/** Get time difference, millisecond */function get_subtraction () {$ t1 = microtime (true); $ t2 = microtime (true); return ($ t2-$1) * 1000 ). 'Ms ';}
/** Microsecond millisecond * returns the number of milliseconds in the timestamp */function get_millisecond () {list ($ usec, $ sec) = explode ("", microtime (); $ msec = round ($ usec * 1000); return $ msec;}/*** returns the string's timestamp in milliseconds */function get_total_millisecond () {$ time = explode ("", microtime (); $ time = $ time [1]. ($ time [0] * 1000); $ time2 = explode (". ", $ time); $ time = $ time2 [0]; return $ time;}/*** returns the current Unix timestamp and the number of microseconds (expressed in seconds) floating point number representation, which is often used to calculate the code snippet execution time */function microtime_float () {list ($ usec, $ sec) = explode ("", microtime (); return (float) $ usec + (float) $ sec );}

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.