我想在當前日期添加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));
我想在當前日期添加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));
這應該是答案
echo date("Y/m/d h:i:s", strtotime("+30 minutes"));
strtotime
預計時間戳作爲其第二個參數,而不是一個格式化的日期。但在任何情況下,你可以使用時間戳工作:
$newdate = date("Y-m-d H:i:s", time()+30*60);
這是因爲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)));
嘗試這個
$curDate = date('Y-m-d', strtotime("+30 minutes", strtotime(date('Y-m-d'))));
$now = time();
$later = $now + 60*30;