运行脚本并确定我的执行时间。在计算时间时我得到负数。我希望它在执行时给我一个肯定的。
<?php
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
echo "executed";
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
$minutes = (int)($totaltime/60)-$hours*60;
echo "This page was created in ".$minutes." minute/s";
?>
答案 0 :(得分:5)
microtime()
作为字符串返回。尝试传入true以使其返回浮点值。这也会将您的代码缩短为:
$starttime = microtime(true);
echo "Executed";
$endtime = microtime(true);
$totaltime = $endtime - $starttime;
$minutes = intval(ceil(($endtime - $starttime) / 60));
echo "This page was created in " . $minutes . " minute(s)";
...