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

The above code returns 2012-10-08, which is incorrect - the first monday of october 2012 should return 2012-10-01.

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.

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)!

Any ideas?

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 に答える