如何在PHP中获得下个月? [英] How to get the next month in PHP?

查看:101
本文介绍了如何在PHP中获得下个月?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来计算下个月份:

I'm currently using the following code to calculate the next month:

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

如果当前日期是3月31日(03),这段代码给了我05距当前日期2个月。我想要它返回四月(04)。

If the current date is March 31 (03), this code gives me "05" which is actually 2 months away from the current date. I would like it to return April (04) instead.

如何实现这一点?

推荐答案

如何尝试这样做:

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

Dins

这篇关于如何在PHP中获得下个月?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆