microtime 返回当前 Unix 时间戳和微秒数

发表日期:2021-07-01 08:55:27 | 来源: | | 浏览(720) 分类:Date/Time 函数

microtime

(PHP 4, PHP 5, PHP 7, PHP 8)

microtime返回当前 Unix 时间戳和微秒数

说明

microtime(bool $get_as_float = ?): mixed

microtime() 当前 Unix 时间戳以及微秒数。本函数仅在支持 gettimeofday() 系统调用的操作系统下可用。

如果调用时不带可选参数,本函数以 "msec sec" 的格式返回一个字符串,其中 sec 是自 Unix 纪元(0:00:00 January 1, 1970 GMT)起到现在的秒数,msec 是微秒部分。字符串的两部分都是以秒为单位返回的。

如果给出了 get_as_float 参数并且其值等价于 truemicrotime() 将返回一个浮点数。

注意: get_as_float 参数是 PHP 5.0.0 新加的。

示例 #1 用 microtime() 对脚本的运行计时

<?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 whileusleep(100);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "Did nothing in $time seconds\n";
?>

参见 time()

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。