如何使用PHP获取下个月的数据?
我目前正在使用以下代码计算下个月:如何使用PHP获取下个月的数据?,php,date,strtotime,Php,Date,Strtotime,我目前正在使用以下代码计算下个月: $nextMonth = date("m",strtotime("+1 months")); 如果当前日期为03年3月31日,则此代码给出的“05”实际上距离当前日期还有2个月。我希望它能在4月(04日)返回 我怎样才能做到这一点呢?试试这个怎么样: $d = new DateTime(date("Y-m-d")); $d->modify( 'first day of next month' ); echo $d->format( 'F' ),
$nextMonth = date("m",strtotime("+1 months"));
如果当前日期为03年3月31日,则此代码给出的“05”实际上距离当前日期还有2个月。我希望它能在4月(04日)返回
我怎样才能做到这一点呢?试试这个怎么样:
$d = new DateTime(date("Y-m-d"));
$d->modify( 'first day of next month' );
echo $d->format( 'F' ), "\n";
DinsPHP日期函数不能很好地实现这一点。您必须自己进行计算,或者可以找到一个库来进行计算。我建议您尝试使用ZF Date类。