我有这样的时间12:00:00 AM怎么加上+两个小时的时间


I have time like this 12:00:00 AM how to add + two hours with the time

我有这样的时间10:00:00 AM怎么加上两个小时的时间。

我已经试过了:

$today = "10:00:00 am"; 
$starttime = "02:00:00"; 
$endtime = date("g:i:s a", $starttime+$today);
echo $endtime;

I vanilla PHP,对象样式使用DataTime()

$date = new DateTime('10:00:00 AM');
$date->modify('+2 hours');
echo $date->format("g:i:s a");
输出:

12:00:00 pm

或者您可以尝试lib Ouzo goodies,并以流畅的方式完成:

echo Clock::at('10:00:00 AM')->plusHours(2)->format("g:i:s a");
输出:

12:00:00 pm

试试这个。如果它工作

 $endtime = date("g:i:s a", strtotime('+2 hours', $starttime + $today));

更多面向对象的方法是使用DateTimeDateInterval

$start_date = new DateTime($result->start_date);
$start_date->add(new DateInterval('P' . (int)$probation_length . 'M'));

根据需要调整

试试这个

<?php
$today = "10:00:00 am"; 
$endtime = date("g:i:s a", strtotime("+2 hours",strtotime($today)));
echo $endtime;
?>

添加& # 39;x # 39;截至日期的小时数

试试这个:

$today = "10:00:00 am"; 
$starttime = "02:00:00"; 
$endtime = date("g:i:s a", strtotime("+2 hours", $starttime + $today));
echo $endtime;