简体   繁体   English

用微秒的php增加一些时间

[英]add some hours to time with microseconds php

HI I need to add 8 hours in the time which i have formatted like below 嗨,我需要在格式如下所示的时间内增加8小时

            $t = microtime(true);
            $micro = sprintf("%06d",($t - floor($t)) * 1000000);
            $d = new DateTime( date('Y-m-d H:i:s.'.$micro, $t) );
            $d->format("Y-m-d H:i:s.u")   // 2015-03-02 07:37:18.715271

i use this format because i need to show microseconds also. 我使用这种格式,因为我还需要显示微秒。 Now i need to add 8 hours in this .Can you please suggest me how can i do this. 现在我需要在其中添加8个小时 。您能建议我该怎么做。

thanks 谢谢

$t = microtime(true);
$micro = sprintf("%06d",($t - floor($t)) * 1000000);
$d = new DateTime( date('Y-m-d H:i:s.'.$micro, $t) );
print $date = $d->format("Y-m-d H:i:s.u");
print $new_time = date("Y-m-d H:i:s".$micro, strtotime($date.'+8 hours'));

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

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