PHP gets the milliseconds of the current time

巴扎黑
Release: 2016-11-24 09:15:38
Original
4299 people have browsed it

1 second = 1000 millisecond = 1000,000 microsecond = 1000,000,000 nanosecond

     php的毫秒是没有默认函数的,但提供了一个microtime()函数,该函数返回包含两个元素,一个是秒数,一个是小数表示的毫秒数,借助此函数,可以很容易定义一个返回毫秒数的函数,例如:

    /*
         * 获取时间差,毫秒级
         */
        function get_subtraction()
        {
                $t1 = microtime(true);
                $t2 = microtime(true);
                return (($t2-$1)*1000).'ms';
        }
Copy after login
    /*
         * microsecond 微秒     millisecond 毫秒
         *返回时间戳的毫秒数部分
         */
        function get_millisecond()
        {
                list($usec, $sec) = explode(" ", microtime());
                $msec=round($usec*1000);
                return $msec;
                 
        }
         
        /*
         *
         *返回字符串的毫秒数时间戳
         */
        function get_total_millisecond()
        {
                $time = explode (" ", microtime () ); 
                $time = $time [1] . ($time [0] * 1000); 
                $time2 = explode ( ".", $time ); 
                $time = $time2 [0];
                return $time;
        }
    
        /*
         *
         *返回当前 Unix 时间戳和微秒数(用秒的小数表示)浮点数表示,常用来计算代码段执行时间
         */
         
        function microtime_float()
        {
            list($usec, $sec) = explode(" ", microtime());
            return ((float)$usec + (float)$sec);
        }
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!