【问题标题】:php microsecondsphp微秒
【发布时间】:2009-04-21 14:42:59
【问题描述】:

我正在使用
echo date('H:i:s')." this step time\n";
为了知道每个函数需要多少时间才能执行。

我怎样才能知道微秒的时间?

【问题讨论】:

    标签: php datetime


    【解决方案1】:

    补充一下,还有PHP的microtime()函数,可以这样使用:

    $time_start = microtime(true);
    
    //do stuff here
    
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    
    echo "It took $time seconds\n";
    

    【讨论】:

      【解决方案2】:
      u 微秒(PHP 5.2.2 中添加)

      查看http://no.php.net/manual/en/function.date.php了解更多信息。

      【讨论】:

      • 我试过date('H:i:s.u'),但我总是得到000000微秒。
      • 格式说明符 'u' 不适用于日期函数,即使在 PHP 5.4.21 中也是如此。您需要编写一个包装器以使其工作。我用这个:gist.github.com/m-manu/6248802
      • 即使我使用建议的 DateTime() 和 ->format() 来获取 'u' 参数,我仍然在 PHP 5.3.2 上得到 000000。因此,即使到该 PHP 版本,此功能也不能正常工作。人们可能不得不使用 Manu 的解决方法。
      【解决方案3】:

      使用格式中的“u”标记表示毫秒。

      【讨论】:

        猜你喜欢
        • 2013-04-18
        • 2010-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-25
        • 1970-01-01
        相关资源
        最近更新 更多