2013-09-24 27 views
-1

我想在当前日期添加30分钟。但是,如果我这样做,它会显示1970-01-01 01:03:33(Unix时间戳)。如何以strtotime()解析器能够理解的格式检索结果?如何使用php添加mintues日期?

这里是我的代码:

$date1  = date("Y-m-d H:i:s"); 
$newdate = date("Y-m-d H:i:s", strtotime('+30 minutes', $date1)); 

回答

0

这应该是答案

echo date("Y/m/d h:i:s", strtotime("+30 minutes")); 
0

strtotime预计时间戳作为其第二个参数,而不是一个格式化的日期。但在任何情况下,你可以使用时间戳工作:

$newdate = date("Y-m-d H:i:s", time()+30*60); 
1

这是因为date()返回一个字符串,并且要添加30分钟到一个字符串,而不是一个日期。 试试这个:

$newdate = date("Y-m-d H:i:s", strtotime('+30 minutes', now())); 

$date1  = date("Y-m-d H:i:s"); 
$newdate = date("Y-m-d H:i:s", strtotime('+30 minutes', strtotime($date1))); 
0

尝试这个

$curDate = date('Y-m-d', strtotime("+30 minutes", strtotime(date('Y-m-d')))); 
0
$now  = time(); 
$later = $now + 60*30;