2011-06-14 92 views
5

我遇到了php数据函数的麻烦。PHP日期函数

echo strtotime(“31/05/2011”);

它打印空白。

这是什么问题?

谢谢。

+0

的[的strtotime()抛出假上格式化的日期]可能重复(http://stackoverflow.com/questions/5736205/strtotime-throws-false-on-a-formatted-date) – Gordon 2011-06-14 15:20:26

+0

问题你没有读过[用于'strtotime'的PHP手册中的第三个注释](http://php.net/manual/en/function.strtotime.php#refsect1-function.strtotime-notes),解释了什么是 – Gordon 2011-06-14 15:21:54

+0

@Gordon。谢谢你的回答。非常感谢。我已将日期格式更改为“ - ”。 – 2011-06-14 15:29:53

回答

4

DD/MM/YYYY是不是一个有效date format(手动概括它必须遵循supported date and time formats之一。)所以,相反,它应该是MM/DD/YYYY:

echo strtotime("05/31/2011"); 

或者,我想为其他人发布,欧洲(ISO8601不缩)版本使用连字符:

echo strtotime("31-05-2011"); 
1

对于欧洲格式的日期(DD-MM-YYYY)使用破折号没有斜杠:

echo strtotime('31-05-2011'); 
1

有关使用PHP的DateTime功能如何?

DateTime::createFromFormat('d/m/Y', '31/05/2011');