[英]add some hours to time with microseconds php
嗨,我需要在格式如下所示的时间内增加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
我使用这种格式,因为我还需要显示微秒。 现在我需要在其中添加8个小时 。您能建议我该怎么做。
谢谢
$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.