我試圖生成日期 (從現在開始後7個月),這裏是我的代碼不能DateTime對象轉換爲字符串
這給錯誤:
PHP Catchable fatal error:
Object of class DateTime could not be converted to string
它正在與在...之前...有什麼問題?
我試圖生成日期 (從現在開始後7個月),這裏是我的代碼不能DateTime對象轉換爲字符串
這給錯誤:
PHP Catchable fatal error:
Object of class DateTime could not be converted to string
它正在與在...之前...有什麼問題?
DateTime類沒有魔法__toString(),所以你不能使用這個對象作爲字符串。
您應該使用getTimestamp()
$cdate = new DateTime("+7 months");
$expiry_date = $cdate->getTimestamp();
PHP致命錯誤:調用成員函數getTimestamp() –
@ManMann,答案更新。 – sectus
$cdate = new DateTime(+7 months);
$cdate = $cdate->format('Y-m-d');
會造成CDate將是一個字符串,如果這就是你要的東西。
你確定這些行有錯誤嗎? http://3v4l.org/VAFii – sectus
你在哪裏初始化$ moe? – shark
適合我 - http://codepad.org/oR33GWGN –