2013-05-08 50 views
0

根據PHP documentation,我正確使用了strtotime,但顯然我設法弄錯了一些東西。當我刪除一個月時,strtotime返回1970年?

以下代碼:

echo date("Y,n,j", strtotime($event["StartDate"])); 

輸出:2013,4,18(這是正確的)

而下面的代碼(使用完全相同的數據):

echo date("Y,n,j", strtotime('-1 month', $event["StartDate"])); 

輸出:1969,12,1(代替2013,3,18

爲什麼?

+3

您是否需要在另一個strtotime調用中包裝$ event ['StartDate']'? – andrewsi 2013-05-08 14:44:58

+0

爲了避免潛在的歧義,最好使用ISO 8601(YYYY-MM-DD)_ [來源](http://php.net/manual/en/function.strtotime.php#refsect1-function)。的strtotime-NOTES) – 2013-05-08 14:47:28

回答

4

echo date("Y,n,j", strtotime('-1 month', strtotime($event["StartDate"])));

相關問題