如何将PHP日期字符串从Y / m / d转换为Y-m-d [关闭]

I have a string that's currently 16/06/2012 and I'd like to convert it into 2012-06-16.

How do I do this?

$date_array = explode("/","16/06/2012");

$new_date = $date_array[2]."-".$date_array[1]."-".$date_array[0];
date("Y-m-d", strtotime(implode("/", array_reverse(explode("/", "16/06/2012")))))

$riqi = "20160920";
$date=date_create($riqi);
echo date_format($date,"Y-m-d");

$riqi = "20160920";
$date=date_create($riqi);
echo date_format($date,"Y-m-d"); //2016-09-20

$riqi = "2016/09/20";
$date=date_create($riqi);
echo date_format($date,"Y-m-d"); //2016-09-20