2016-11-08 50 views
0

我使用以下代碼將用戶選擇的日期轉換爲以下日期格式以進行保存。但它不會轉換2017年。它把它作爲2016年如何將日期轉換爲正確的格式?

$pieces = explode(" ", $start); 
$new_date_in = date("Y-m-d",strtotime($pieces[2]." ".$pieces[1]." ".$pieces[0])); 

當我贊同$開始,它給週三2017年3月8日

但是當我回聲$ new_date_in,它給2016年3月9日

2016日期將其正確轉換。請給我一個解決方案。

+0

那麼你認爲什麼是'$件[0]'' – RiggsFolly

+0

月08日Wed' ??? – AbraCadaver

+0

'$ new_date_in = date(「Y-m-d」,strtotime($ pieces [2]。「」。$ pieces [1]。「」。$ pieces [3]));' – RiggsFolly

回答

1
$pieces = explode(" ", $start); 
$new_date_in = date("Y-m-d",strtotime($pieces[2]." ".$pieces[1]." ".$pieces[3])); 
0

您正在使用錯誤的零件並傳遞08 Mar Wedstrtotime()很不錯。只需使用$start

$new_date_in = date("Y-m-d", strtotime($start)); 
相關問題