开发者

PHP microtime()

开发者 https://www.devze.com 2023-01-19 19:01 出处:网络
Here is my code: <? 开发者_开发知识库 $time = microtime(); $len = strlen($time); echo $time; echo\"<br>\".$len.\"<br>\";

Here is my code:

<?
   开发者_开发知识库 $time = microtime();
    $len = strlen($time);
    echo $time;
    echo"<br>".$len."<br>";
    $micro;
    $i = 0;
    while ($time{$i} != " ")
    {
        $micro{i}=$time{i};
        echo $micro{i};
        $i=$i+1;
    }
?>

The output I'm getting is 0000000000 (that is $micro). Here I'm trying to get the microseconds part of the output.

Is there anything wrong?


Use microtime(true) instead.

$time = microtime(true);
$micro = $time - floor($time); // microseconds part


Use $micro{$i}=$time{$i}; instead of $micro{i}=$time{i};

But much better way to do stuff like this:

list($timestamp, $microseconds) = split(" ", microtime());

0

精彩评论

暂无评论...
验证码 换一张
取 消