php - Strtotime() 不适用于 dd/mm/YYYY 格式

标签 php

我真的很喜欢 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/

相关文章:

php - JavaScript 表单已提交,但发布数据在 PHP 中不可用

php - MP3流/下载网站-Apache服务器内存问题

php - laravel 从数据库读取数据返回重复结果

javascript - 文本区域值为 NULL javascript

php - Laravel 查询关系模型::有 ('relation' ) 不起作用

javascript - BrainTree Sandbox 返回验证错误 : - Unknown paymentMethodNonce

php - 为什么 02000 被评估为 1024

php - 从 POST 传递带有换行符的字符串时,Textarea 没有更新?

php - 这些 PHPDOC 属性的用途是什么?

php - WordPress 自定义查询