加上"x"小时数
问题描述:
我目前有php像这样返回当前日期/时间:
I currently have php returning the current date/time like so:
$now = date("Y-m-d H:m:s");
我想做的是有一个新变量$new_time
等于$now + $hours
,其中$hours
是从24到800的小时数.
What I'd like to do is have a new variable $new_time
equal $now + $hours
, where $hours
is a number of hours ranging from 24 to 800.
有什么建议吗?
答
您可以使用.
如果函数中需要变量,则必须使用双引号,然后使用strtotime("+{$hours} hours")
,但是最好使用strtotime(sprintf("+%d hours", $hours))
.
If you need variables in the function, you must use double quotes then like strtotime("+{$hours} hours")
, however better you use strtotime(sprintf("+%d hours", $hours))
then.