Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP获取下个月的数据?_Php_Date_Strtotime - Fatal编程技术网

如何使用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";

Dins

PHP日期函数不能很好地实现这一点。您必须自己进行计算,或者可以找到一个库来进行计算。我建议您尝试使用ZF Date类。