且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP日期返回错误月份减去一个月

更新时间:2022-11-13 20:49:30

strtotime() code>使用30天,二月(今年)只有28天,所以不会在二月份生效。您可以使用当前日期 d j ,并减去将始终将您放在上个月( -29天):

strtotime() uses 30 day months and there are only 28 in days in February (this year) so will not yield a valid date in February. You could use the current day d or j and subtract that which will always put you in the previous month (-29 days):

$prevmonth = date('M', strtotime('-' . date('d') . ' days'));

这将获得 12月 January