2013-09-24 25 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;