好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

PHP获得毫秒的时间microtime()用法 - php日期

PHP获得毫秒的时间microtime()用法

在php中如果我们要获取毫秒就必须通过microtime()再进行转换,下面我来给各位朋友举几个实例,希望对大家会有所帮助。

问题不怕弱智…啥都记,代码如下:

function  getmicrotime()    {        list( $usec ,  $sec ) =  explode ( " " ,microtime());         return  ((float) $usec  + (float) $sec );    } 

空格后面为当前的时间戳,空格前面是当前的精确时间,例,计算页面执行时间函数,代码如下:

<?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" ;  ?> 

查看更多关于PHP获得毫秒的时间microtime()用法 - php日期的详细内容...

  阅读:61次