在php中添加持续时间



我的开始时间是上午08:15。我想在我的开始时间中增加01:00(1小时)的持续时间,以便最终时间是上午09:15。如何做到这一点?

持续时间和开始时间可能会有所不同。持续时间仅为00:30、01:00、01:15…格式

感谢

试试这个-

$time = "08:15 AM";
$date = date("h:i A", strtotime($time." + 1 hour"));

或者如果你想增加分钟数,那么-

$time = "08:15 AM";
$date = date("h:i A", strtotime($time." + 90 minutes"));
date('H:i', strtotime('+30 minutes'));

以下是您的解决方案:

如果你只是使用当前时间,

$date = date('h:i:s A', time()+3600);

如果您使用的是strtotime(),它会返回一个数字,表示以秒为单位的时间。要增加它,请添加要添加的相应秒数。

在这种情况下,写下这行:

$today = time(); // or give your time here that is 08:15
$date = date('h:i:s A', strtotime($today)+36000); // $today is today date

最新更新