如果您有足够高的版本号,可以轻松实现:
$when = new DateTime($start_time);
$when->modify('+' . $duration);
echo 'End time: ' . $when->format('Y-m-d h:i:s') . "\n";
Run Code Online (Sandbox Code Playgroud)
使用strtotime(),您可以将当前时间(2009-09-25 15:00:00)转换为时间戳,然后将(60*60*3 = 3小时)添加到时间戳.最后只需将其转换回您想要的任何时间.
//Start date
$date = '2009-09-25 15:00:00';
//plus time
$plus = 60 * 60 * 3;
//Add them
$time = strtotime($date) + $plus;
//Print out new time in whatever format you want
print date("F j, Y, g:i a", $time);
Run Code Online (Sandbox Code Playgroud)