Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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 - Fatal编程技术网

如何在php中显示下个月

如何在php中显示下个月,php,Php,我希望输出为“2018-03-15”; 但是此代码不起作用。您可以使用strotime $date ="2018-02-15"; $next_month = date('$date', strtotime('+1 month'); echo "$next_month"; 结果将是: $date ="2018-02-15"; $time = strtotime($date); $next_month = date("Y-m-d", strtotime("+1 month", $time));

我希望输出为
“2018-03-15”

但是此代码不起作用。

您可以使用
strotime

$date ="2018-02-15";
$next_month = date('$date', strtotime('+1 month');

echo "$next_month";
结果将是:

$date ="2018-02-15";
$time = strtotime($date);
$next_month = date("Y-m-d", strtotime("+1 month", $time));

echo $next_month;
文档:

使用以下内容:

2018-03-15 
$date ="2018-04-22";
$next_month = date('Y-m-d', strtotime($date.' +1 month'));
echo "$next_month";