更新时间:2022-05-04 23:03:09
m/d/y
或d-m-y
格式的日期通过查找消除歧义在各个组件之间的分隔符处:如果分隔符是一个斜线(/
),则假定为美国m/d/y
;而如果分隔符是破折号 (-
) 或点 (.
),然后是欧洲的d-m-y
假定格式.查看更多信息.
Dates in the
m/d/y
ord-m-y
formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/
), then the Americanm/d/y
is assumed; whereas if the separator is a dash (-
) or a dot (.
), then the Europeand-m-y
format is assumed. Check more here.
使用默认的日期函数.
$var = "20/04/2012";
echo date("Y-m-d", strtotime($var) );
编辑 我刚刚测试了它,不知何故,PHP 不能很好地处理 dd/mm/yyyy 格式.这是另一种解决方案.
EDIT I just tested it, and somehow, PHP doesn't work well with dd/mm/yyyy format. Here's another solution.
$var = '20/04/2012';
$date = str_replace('/', '-', $var);
echo date('Y-m-d', strtotime($date));