如何在现有时间内添加45分钟?

时间:2014-05-27 05:08:07

标签: php strtotime

我正在尝试使用strtotime.i添加两次使用以下代码添加两次 我的预期输出为15:59:00但它给了我09:30:44。那有什么问题?

提前致谢。

$json['time'] = "15:14";   
$total_duration = "45";   //in minutes
/* convert minutes into hours-minutes */
$hours = intval($total_duration / 60);  
$mins = $total_duration % 60;           
$service_duration = strtotime($hours."00:00")+strtotime("00:".$mins.":00");

/* end time = total service duration + start time */
$start_time = strtotime($json['time'].":00");

echo $service_duration."--".$start_time."==";
$end_time2 = $start_time+$service_duration;   
$end_time = date('H:i:s', $end_time2);echo $end_time;exit;

1 个答案:

答案 0 :(得分:3)

你可以这样做

$json['time'] = "15:14";   
$total_duration = "45";   //in minutes
$endTime = strtotime("+".$total_duration." minutes", strtotime($json['time']));
echo date('H:i:s', $endTime);

输出:

15:59:00