如何获得下个月的PHP


How to get the next month in PHP?

我目前使用以下代码来计算下个月:

$nextMonth = date("m",strtotime("+1 months"));

如果当前日期是3月31日(03),此代码给出的"05"实际上距离当前日期有2个月的距离。我希望它返回四月(04)。

我怎样才能做到这一点?

试试这个:

$d = new DateTime(date("Y-m-d"));
$d->modify( 'first day of next month' );
echo $d->format( 'F' ), "'n";

din