Strtotime()不适用于dd/mm/YYYY格式 [英] Strtotime() doesn't work with dd/mm/YYYY format

查看:80
本文介绍了Strtotime()不适用于dd/mm/YYYY格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢strtotime()函数,但是用户手册没有完整介绍受支持的日期格式. strtotime('dd/mm/YYYY')不起作用,仅适用于mm/dd/YYYY格式.

I really like the strtotime() function, but the user manual doesn't give a complete description of the supported date formats. strtotime('dd/mm/YYYY') doesn't work, it works only with mm/dd/YYYY format.

如果日期格式为dd/mm/YYYY,如何将其转换为YYYY-mm-dd? 我可以使用explode()函数来做到这一点,但我认为有更好的解决方案.

If I have date in dd/mm/YYYY format, how can I convert it to YYYY-mm-dd? I can do it by using explode() function, but I think there are better solutions.

推荐答案

以下是简化的解决方案:

Here is the simplified solution:

$date = '25/05/2010';
$date = str_replace('/', '-', $date);
echo date('Y-m-d', strtotime($date));

结果:

2010-05-25

strtotime文档内容如下:

The strtotime documentation reads:

通过查看之间的分隔符来区分 m/d/y dmy 格式的日期各个组成部分:如果分隔符是斜杠(/),则假定使用美国 m/d/y ;而如果分隔符是破折号(-)或点(.),则采用欧洲 dmy 格式是假定的.

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.

这篇关于Strtotime()不适用于dd/mm/YYYY格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆