這是我的計劃:錯誤日期解決方案
$newEndingDate = strtotime(date("Y-m-d", strtotime($row['startdate']))."+1 year");
echo $newEndingDate;
這是我的錯誤
1332441000
什麼錯誤
這是我的計劃:錯誤日期解決方案
$newEndingDate = strtotime(date("Y-m-d", strtotime($row['startdate']))."+1 year");
echo $newEndingDate;
這是我的錯誤
1332441000
什麼錯誤
的strtotime()
函數返回一個UNIX Timestamp:1970-01-01以來的秒數。
你所得到的數字是不是一個錯誤:它只是意味着,自1970年以來
1332441000秒已經過去了。如果有必要,可以使用date()
功能格式化該時間戳,得到一個字符串看起來更加用戶友好。
例如:
echo date('Y-m-d H:i:s', $newEndingDate);
應該得到以下結果:
2012-03-22 19:30:00
它的strtotime功能,這是的返回值UNIX時間戳。該秒鐘過去了01/01/1970
我覺得這是你想獲得:
$newEndingDate = date('Y-m-d', strtotime('+ 1 year', strtotime($row['startdate'])));
嘗試使用mktime做你想做什麼。假設$row['startdate'] == '2011-01-01'
$mydate = strtotime($row['startdate']);
$newEndingDate = mktime(date("H", $mydate), date("i", $mydate), date("s", $mydate), date("n", $mydate), date("j", $mydate), date("Y", $mydate) + 1);
echo date('Y-m-d', $newEndingDate); //2012-01-01
你在做什麼不會給你以後,因爲你不能做到以下是結果:
strotime('2011-01-01+1 year');
試試這個:
$mydate = strtotime($row['startdate']);
$newEndingDate = date('Y-m-d', strtotime("+1 year", $mydate));
echo $newEndingDate; //2012-01-01
你沒有得到一個錯誤,你得到自1970/01/01以來已經過去的所有秒的時間戳
如果你需要一個可讀的格式嘗試:
$date = date("Y-m-d H:i:s", $newEndingDate);
這是不是一個錯誤,這是一個時間戳。請參閱['date()'](http://www.php.net/date)瞭解如何將其轉換爲可讀日期 – 2011-03-23 11:39:10