我真的很喜欢 strtotime()
函数,但是用户手册并没有给出支持的日期格式的完整描述。 strtotime('dd/mm/YYYY')
不起作用,它只适用于 mm/dd/YYYY
格式。
如果我有 dd/mm/YYYY
格式的日期,如何将其转换为 YYYY-mm-dd
?
我可以通过使用 explode()
函数来做到这一点,但我认为有更好的解决方案。
最佳答案
这是简化的解决方案:
$date = '25/05/2010';
$date = str_replace('/', '-', $date);
echo date('Y-m-d', strtotime($date));
结果:
2010-05-25
The strtotime
documentation阅读:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.
关于php - Strtotime() 不适用于 dd/mm/YYYY 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2891937/