如何将日期转换为正确的格式?

问题描述:

我使用以下代码将用户选择的日期转换为以下日期格式以进行保存。但它不会转换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

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

您正在使用错误的零件并传递08 Mar Wedstrtotime()很不错。只需使用$start

$new_date_in = date("Y-m-d", strtotime($start));