PHP添加15分钟到时间值 [英] PHP Adding 15 minutes to Time value
问题描述
我有一个表单收到时间值:
I have a form that receives a time value:
$selectedTime = $_REQUEST['time'];
时间是这种格式 - 9:15:00 - 这是上午9:15。然后我需要添加15分钟,并将其存储在一个单独的变量中,但是我被遗弃了。
The time is in this format - 9:15:00 - which is 9:15am. I then need to add 15 minutes to this and store that in a separate variable but I'm stumped.
我试图使用strtotime没有成功,例如:
I'm trying to use strtotime without success, e.g.:
$endTime = strtotime("+15 minutes",strtotime($selectedTime)));
但不会解析。
推荐答案
您的代码无效(解析),因为您有额外的)
在结尾导致解析错误
。计数,你有2 (
和3 )
。如果您修复这个问题,它可以正常工作,但是 strtotime()
返回一个时间戳,所以为了获得一个人类可读的时间,使用 date()
。
Your code doesn't work (parse) because you have an extra )
at the end that causes a parse error
. Count, you have 2 (
and 3 )
. It would work fine if you fix that, but strtotime()
returns a timestamp, so to get a human readable time use date()
.
$selectedTime = "9:15:00";
$endTime = strtotime("+15 minutes", strtotime($selectedTime));
echo date('h:i:s', $endTime);
获取一个编辑器,将语法突出显示,并显示不匹配的括号,大括号等。
Get an editor that will syntax highlight and show unmatched parentheses, braces, etc.
只需直接在没有任何TZ或DST的情况下,添加15分钟(阅读zerkms评论):
To just do straight time without any TZ or DST and add 15 minutes (read zerkms comment):
$endTime = strtotime($selectedTime) + 900; //900 = 15 min X 60 sec
仍然,)
是这里的主要问题。
Still, the )
is the main issue here.
这篇关于PHP添加15分钟到时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!