PHP gets the number of milliseconds in the current time

Source: Internet
Author: User
1 second = millisecond = 1000,000 microsecond = 1000,000,000 nanosecond

PHP has no default function for milliseconds, but it provides a microtime () function that returns two elements, one for seconds, and one for fractional milliseconds, which makes it easy to define a function that returns a number of milliseconds, for example:

         /* Get time difference, millisecond         *        /function get_subtraction ()        {                $t 1 = microtime (true);                $t 2 = Microtime (true);                Return (($t 2-$1) *1000). ' Ms ';        }
  /         * * microsecond microseconds     millisecond milliseconds         * Returns the number of milliseconds for the timestamp */        function Get_millisecond ()        {                list ($ USEC, $sec) = Explode ("", Microtime ());                $msec =round ($usec *1000);                return $msec;                         }                 /*         * *         returns the number of milliseconds in a string time stamp */        function Get_total_millisecond ()        {                $time = explode ("", Microtime ());                 $time = $time [1]. ($time [0] * +);                 $time 2 = Explode (".", $time);                 $time = $time 2 [0];                return $time;        }            /*         *         returns the current Unix timestamp and the number of microseconds (in fractional seconds) of floating-point numbers, commonly used to calculate 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.