PHP 中的 microtime() 函数
phpprogrammingserver side programming更新于 2025/8/7 0:22:17
microtime() 函数返回当前时间的微秒数。它返回当前 Unix 时间戳(带微秒)。此函数仅适用于支持 gettimeofday() 系统调用的操作系统。
语法
microtime(get_as_float)
参数
get_as_float − 调用时不带可选参数,此函数返回字符串"msec sec",其中 sec 是自 Unix 纪元(1970 年 1 月 1 日 0:00:00 GMT)以来的秒数,msec 是微秒部分。如果可选的 get_as_float 设置为 TRUE,则返回浮点数(以秒为单位)。
返回
microtime() 函数返回当前 Unix 时间戳(以微秒为单位)。此函数仅适用于支持 gettimeofday() 系统调用的操作系统。
示例
下面是一个例子 −
<?php echo(microtime()); ?>
输出
0.85623100 1539234951
示例
让我们看另一个例子 −
<?php $time_start = microtime(true); usleep(100); $time_end = microtime(true); $time = $time_end - $time_start; echo "Did nothing in $time seconds
"; ?>
输出
Did nothing in 0.00016498565673828 seconds

