我正在尝试从当前时间到之后的 12 小时制定时间表。我正在使用 date() 函数来检索当前时间,但是如何增加小时数并调整 AM/PM?我可以将 1 添加到 date() 函数吗?
谢谢您的帮助。
$now = time();
$then = $now + 12 * 60 * 60;
echo date(format, $then);
您可以使用strtotime
:
date('d-m-Y H:i:s', strtotime('+1 hour')); // one hour since now
或者
date('d-m-Y H:i:s', strtotime('2011-02-25 14:00:42'));
$mydate = date("dateformat", time() + 43200);
time() 获取当前时间戳,然后添加 43200 即 12 小时 * 60 分钟 * 60 秒