简体   繁体   English

PHP microtime()

[英]PHP microtime()

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). 我得到的输出是0000000000(即$ micro)。 Here I'm trying to get the microseconds part of the output. 在这里,我试图获得输出的微秒部分。

Is there anything wrong? 有什么问题吗?

Use microtime(true) instead. 请改用microtime(true)

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

Use $micro{$i}=$time{$i}; 使用$ micro {$ i} = $ time {$ i}; instead of $micro{i}=$time{i}; 而不是$ micro {i} = $ time {i};

But much better way to do stuff like this: 但是更好的方法来做这样的事情:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM