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'; }
/* * 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); }
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号