简体   繁体   中英

add some hours to time with microseconds php

HI I need to add 8 hours in the time which i have formatted like below

            $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.

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'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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