如何获得下个月的PHP

use*_*236 3 php

我需要用php获取下个月的信息。这些例子无处不在

date('Y-m-t',strtotime("+1 month"))
Run Code Online (Sandbox Code Playgroud)

上面的代码输出为“ 2017-03-31”。我需要二月而不是三月。

Ind*_*yal 8

像这样使用

// One month from today
$date = date('Y-m-d', strtotime('+1 month'));

// One month from a specific date
$date = date('Y-m-d', strtotime('+1 month', strtotime('2015-01-01')));
Run Code Online (Sandbox Code Playgroud)

  • 这可能无法每天按预期工作:“date('Ymd', strtotime('+1month', strtotime('2020-08-31')))”产生“2020-10-01”,因此它跳过月份八月最后一天打电话时的九月。接受的解决方案不存在这个问题。 (4认同)

小智 6

如果要获取下一个而不考虑当前月份中的当前日期。下面的代码可能会帮助您

echo date('M',strtotime('first day of +1 month'));
Run Code Online (Sandbox Code Playgroud)

这会给你“二月”