我需要將日期字符串轉換爲以下格式:「d/m/Y」 要轉換的日期字符串並不總是相同的,有時它的07/02/2014,有時13/02/2014,有時2014-02-07。strtotime在某些日期返回false
我使用這個命令轉換: date("d/m/Y", strtotime($datestring))
我注意到,有時我得到01/01/1970,因爲一個錯誤的認爲的strtotime回報。 我把範圍縮小到這一點: strtotime("07/02/2014")
收益1409605200這是確定.... strtotime("13/02/2014")
返回false !!!!
閱讀所有關於strtotime的帖子,在這裏,在這個論壇。 也該解決方案將沒有幫助,因爲我不知道事先的特定格式:
$a = strptime('22-09-2008', '%d-%m-%Y'); $timestamp = mktime(0, 0, 0, $a['tm_mon']+1, $a['tm_mday'], $a['tm_year']+1900);
這裏有什麼問題? 我需要什麼解決方案?
如果你* *甚至不知道時間格式,如何'strtotime'神奇咋辦?每次都無法正確猜測。 – deceze
仍然沒有回答爲什麼一個13/02/2014失敗,而09日不會... – Rodniko
因爲XX/XX/XXXX被解釋爲M/D/Y。請參閱http://3v4l.org/uYIAu。如果M是13,那顯然會失敗。你確定07/02/2014是否真的被解釋爲「ok」? – deceze