2
 echo date('Y-m-d', strtotime('First Monday '.date('F o', strtotime("-4 months")));

上面的代码返回 2012-10-08,这是不正确的 - 2012 年 10 月的第一个星期一应该返回 2012-10-01。

手册中的变更日志(http://php.net/manual/en/function.strtotime.php)指定以下内容:

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(在 localhost 上运行 xamp)!

有任何想法吗?

4

1 回答 1

7

of尝试检索该月的第一天时缺少关键字

echo date('Y-m-d', strtotime('First Monday of '.date('F o', strtotime("-4 months")));

我在这个错误报告中找到了信息

我当前的版本是 PHP 5.4.4,以防它仍然不适合你

于 2013-02-06T12:17:23.577 回答