如何以特定格式获取下个月的 php?

How do I get next month in php in a specific format?

我想得到下个月,像这样:

如果当前月份是 5 下个月将是 6 OR 如果当前月份是 12 下个月将是 1.

$current_date = date("Y-m-d");
$d = new DateTime($current_date);
$next_month = $d->modify( 'next month' );

现在我得到这个:

object(DateTime)#69 (3) { ["date"]=> string(19) "2015-04-26 00:00:00"

只需使用DateTime::format() 格式化输出。具体使用 n 标志:

$current_date = date("Y-m-d");
$d = new DateTime($current_date);
$next_month = $d->modify( 'next month' );
echo $next_moth->format('n');