strtotime('第一个星期一..')是一个月的第一天,返回错误的日期 [英] strtotime('First Monday ..') when it's the first day of the month returns the wrong date
问题描述
echo date('Y-m-d', strtotime('First Monday '.date('F o', strtotime("-4 months")));
上面的代码返回2012-10-08,这是不正确的-2012年10月的第一个星期一应返回2012-10-01.
The above code returns 2012-10-08, which is incorrect - the first monday of october 2012 should return 2012-10-01.
手册中的变更日志( http://php.net/manual/zh/function.strtotime.php )指定以下内容:
The changelog from the manual (http://php.net/manual/en/function.strtotime.php) specifies the following:
In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a
month where that weekday was the first day of the month would incorrectly add
one week to the returned timestamp.
This has been corrected in 5.2.7 and later versions.
很明显,这是导致错误的返回日期的原因,但是我使用的是PHP版本5.4.7(在本地主机上运行xamp)!
It seems to be clear that this is what's causing the wrong return date, however I'm using PHP version 5.4.7 (running xamp on localhost)!
有什么想法吗?
推荐答案
尝试检索每月的第一天时,您缺少关键字of
You are missing the keyword of
when trying to retrieve the first day of the month
echo date('Y-m-d', strtotime('First Monday of '.date('F o', strtotime("-4 months")));
我在此错误报告中找到了信息
我当前的版本是PHP 5.4.4,以防它仍然对您不起作用
My current version is PHP 5.4.4 in case it still does not work for you
这篇关于strtotime('第一个星期一..')是一个月的第一天,返回错误的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!