php:strtotime("12/31/2004 +6个月")); 没有回到六月的最后一天

use*_*425 5 php strtotime

我期望这个功能返回6/30/2005而不是7/1/2005.

print date("m/d/Y", strtotime("12/31/2004 +6 month"));
Run Code Online (Sandbox Code Playgroud)

同样,print date("m/d/Y", strtotime("1/31/2011 +1 month"))返回03/03/2011时希望它返回2/28/2011.

有没有人知道是否有一种直接的方式来显示添加月份的最后一天?

nic*_*ckb 6

这个怎么样?

echo date("m/d/Y", strtotime("last day of 12/31/2004 + 6 month")); // 6/30/2005
echo date("m/d/Y", strtotime("last day of 1/31/2011 + 1 month")); // 2/28/2011
Run Code Online (Sandbox Code Playgroud)

演示

编辑:供您参考,以下是相关时间文档的链接.