PHP获得毫秒的时间microtime()用法
在php中如果我们要获取毫秒就必须通过microtime()再进行转换,下面我来给各位朋友举几个实例,希望对大家会有所帮助。
问题不怕弱智...啥都记
<?php function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } ?>
其实就是处理了一下microtime()这个函数。
microtime()这个函数的返回值是这种形式:
0.06261400 1303715872
空格后面为当前的时间戳,空格前面是当前的精确时间
例,计算页面执行时间函数
<?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"; ?>
文章网址:http://www.phprm.com/base/55881.html
随意转载^^但请附上教程地址。