2015-07-19 30 views
3

我與CI的工作,併成功地呼應正確的到期日期,但我也收到此錯誤:笨:非合式數值遇到

非合式數值遇到

$expire_datetime = date('g:ia \o\n l jS F Y',strtotime($row->created, "+2weeks")); 
    echo $expire_datetime; 
+0

Check [these](http://stackoverflow.com/questions/6136430/a-non-well-formed-numeric-value-encountered#answers)答案。 – Tpojka

+0

我做過了,我並不完全理解這些答案。 –

+0

也許你想使用'date_format()'函數。檢查[docs](http://php.net/manual/en/datetime.format.php#107757)。 – Tpojka

回答

0

你所有的編碼都是正確的。問題在於+2weeks。當您使用strtotime()功能時,您需要在文本(+2<SPACE>weeks)之間保留<space>

例子(from W3Schools

<?php 
    echo(strtotime("now") . "<br>"); 
    echo(strtotime("3 October 2005") . "<br>"); 
    echo(strtotime("+5 hours") . "<br>"); 
    echo(strtotime("+1 week") . "<br>"); 
    echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "<br>"); 
    echo(strtotime("next Monday") . "<br>"); 
    echo(strtotime("last Sunday")); 
?> 

因此,最終的好形式代碼

$expire_datetime = date('g:ia \o\n l jS F Y',strtotime($row->created, "+2 weeks")); 
0

strtotime()功能需要在第一個參數相對日期格式。第二個參數是可選的,可以是unix時間戳。