Php 下个月发现,上个月给出错误结果

Php 下个月发现,上个月给出错误结果,php,Php,我想找到本月和上个月之后的2个月。我的代码如下: $current = strtotime(date('m',time()) . '-01 00:00:01'); $next_month = date('m', strtotime('+1 month', $current)); $next_next_month = date('m', strtotime('+2 month', $current)); $previous_month = date('m', strtotime('-0 month

我想找到本月和上个月之后的2个月。我的代码如下:

$current = strtotime(date('m',time()) . '-01 00:00:01');
$next_month = date('m', strtotime('+1 month', $current));
$next_next_month = date('m', strtotime('+2 month', $current));
$previous_month = date('m', strtotime('-0 month', $current));

echo $previous_month.$next_month.$next_next_month;

output : 01 02 03
我想得到本月的结果。预期输出为
04 05 06

如何实现这一结果。有什么解决办法吗。谢谢

$m = date('m');
printf("%02d %02d %02d", ($m+10) % 12 + 1, $m, $m % 12 + 1);
产出(4月2日):

03 04 05


这可能是因为您没有在
$current
中使用年份,您是否尝试过
$current=strottime(日期('Y-m')。-01 00:00:01')?如果没有年份,则可能是无效日期。
$current
的值是多少?另外,我认为对于
$previous\u month
你应该使用
-1 month
而不是
-0
@rickdenhaan:谢谢你,伙计。这很有效。