我几乎尝试了10个小时来更改日期格式,以适应我的需求,但无法成功。我已经用以下示例尝试了Preg_Replace Strotime函数。PHP正则表达式更改日期格式
当前的日期格式为:2006年2月25日 要转换为:2006-02-25
以下是我已经试过的例子名单:
publishdate = "02-20-2012";
echo preg_replace("/\d{2}-\d{2}-\d{4}/","$3/$1/$2",$publishdate);
$dateString= '2006-09-14';
echo date("m/d/Y", strtotime($dateString));
$dateString1= '02-20-2012';
echo date("Y/m/d", strtotime($dateString1));
$date1 = '05-25-2010';
echo date('Y-m-d', strtotime($date1));
$dateString2= '02-20-2012';
echo preg_replace("/(\d{2})-(\d{4})-(\d{2})/","$2/$3/$1",$dateString2);