PHP转换日期格式dd / mm / yyyy => yyyy-mm-dd [英] PHP convert date format dd/mm/yyyy => yyyy-mm-dd

查看:246
本文介绍了PHP转换日期格式dd / mm / yyyy => yyyy-mm-dd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

PHP日期字符串格式

我正在尝试将日期从 dd / mm / yyyy => yyyy-mm-dd 。我使用了mktime()函数和其他函数,但我似乎无法使其工作。我使用'/'作为分隔符设置了爆炸原始日期,但是我没有成功更改格式和将'/'' - '交换。

I am trying to convert a date from dd/mm/yyyy => yyyy-mm-dd. I have using the mktime() function and other functions but I cannot seem to make it work. I have managed to explode the original date using '/' as the delimiter but I have no success changing the format and swapping the '/' with a '-'.

任何帮助将不胜感激。

Any help will be greatly appreciated.

推荐答案


日期在 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. 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));

这篇关于PHP转换日期格式dd / mm / yyyy => yyyy-mm-dd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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