【发布时间】:2011-11-17 01:48:33
【问题描述】:
我正在尝试将 15 分钟添加到当前时间。我正在使用以下代码:
$curtime = date('H:i');
$newtime = $curtime + strtotime('+15 minutes');
但这仍然只打印当前时间,而不是当前时间 + 15。
我希望它像这样增加 15 分钟
例如如果时间为 12:30,则添加后的时间为 12:45
谢谢。
【问题讨论】:
我正在尝试将 15 分钟添加到当前时间。我正在使用以下代码:
$curtime = date('H:i');
$newtime = $curtime + strtotime('+15 minutes');
但这仍然只打印当前时间,而不是当前时间 + 15。
我希望它像这样增加 15 分钟
例如如果时间为 12:30,则添加后的时间为 12:45
谢谢。
【问题讨论】:
关闭,你想要:
$new_time = date('H:i', strtotime('+15 minutes'));
【讨论】:
你可以这样做:
echo date('H:i', (time() + (15 * 60)));
【讨论】:
试试这个:
$curtime = date('H:i');
$newtime = strtotime($curtime) + (15 * 60);
echo date('H:i', $newtime);
【讨论】:
你可以试试这个 - strtotime("+15 minutes")
【讨论】:
如果有人想让它以面向对象的方式工作,这里是解决方案:
$currentTime = new DateTime();
$currentTime->add(new TimeInterval('PT15M'));
// print the time
echo $currentTime->format('H:i');
需要 PHP >= 5.3
【讨论】: