Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中为时间添加微秒_Php_Time - Fatal编程技术网

在php中为时间添加微秒

在php中为时间添加微秒,php,time,Php,Time,这是我用来以微秒计算当前时间的代码 $time=date("Y-m-d\TH:i:s") . substr((string)microtime(), 1, 8); 我需要通过添加一些以微秒为单位的值来更改以$time为单位的值。是否可以将微秒添加到时间?? 实际上,我需要创建一个模拟器,在这里我需要检查在一秒钟的时间间隔内执行了多少次,并找出执行需要多少微秒。您可以为像这样的旧版本构建一个回退功能。它只在当前时间有效 function udate($format, $utimestamp =

这是我用来以微秒计算当前时间的代码

 $time=date("Y-m-d\TH:i:s") . substr((string)microtime(), 1, 8);
我需要通过添加一些以微秒为单位的值来更改以$time为单位的值。是否可以将微秒添加到时间??
实际上,我需要创建一个模拟器,在这里我需要检查在一秒钟的时间间隔内执行了多少次,并找出执行需要多少微秒。

您可以为像这样的旧版本构建一个回退功能。它只在当前时间有效

function udate($format, $utimestamp = null){
                if(is_null($utimestamp)){
                    $utimestamp = microtime(true);
                    $timestamp = floor($utimestamp);
                    $milliseconds = round(($utimestamp - $timestamp) * 1000000);
                    return date(str_replace("u",$milliseconds,$format), $timestamp);
                }else
                    return date($format, $utimestamp);
            }

echo udate('Y-m-d H:i:s.u');

微秒有一个格式字符u是的,@Pavel是对的。。。在PHP5.2.2中添加了微秒。如何向变量添加微秒值?是否可能?向变量添加值是什么意思?连接字符串?你已经在做了。您可以添加两个浮动-只需将日期转换为1970年以来的秒数,并将微时间标准化。但要注意浮点运算。$time=dateY-m-d\TH:i:s。亚字符串微时间,1,8;我需要在$time上加200微秒。可能吗?