This seems to be special case for months with 31 days: Note that '-1 month' may produce unexpected result when used in last day of month that has 31 days (from http://www.php.net/manual/de/datetime.formats.relative.php#102947) What you can do is:
$date = new DateTime('last day of last month'); // this is "2012-04-30" now
/// 'first day of last month' would work either, of course
And then it depends on what you are going to do with the date.
3条答案
按热度按时间bxjv4tth1#
This seems to be special case for months with 31 days:
Note that '-1 month' may produce unexpected result when used in last day of month that has 31 days (from http://www.php.net/manual/de/datetime.formats.relative.php#102947)
What you can do is:
And then it depends on what you are going to do with the date.
6qfn3psc2#
我认为您需要有一个已经存在的日期时间并修改它,如下所示:
n53p2ov03#
这是一个代码块,我希望它能有所帮助:
今天注意的是:2022-12-05