昨天运行良好,没有更改代码。

echo date("M", strtotime("-3 month", time()) );
echo date("M", strtotime("-2 month", time()) );
echo date("M", strtotime("-1 month", time()) );
echo date("M", time());

它昨天生产的输出符合您的预期-即4月,5月,6月,7月

今天 echo 五月五月七月七月

有任何想法吗?

提前致谢。

最佳答案

可能与bug #44073有关

您可以尝试这样的事情:

echo date("M", strtotime("-3 month", strtotime(date("F") . "1")) ) . "\n";
echo date("M", strtotime("-2 month", strtotime(date("F") . "1")) ) . "\n";
echo date("M", strtotime("-1 month", strtotime(date("F") . "1")) ) . "\n";
echo date("M", time()) . "\n";

(解决方案可在 strtotime 的注释部分中找到; direct link)

并输出:
Apr
May
Jun
Jul

带有日期格式和月份名称以及所有其他内容的“作弊”类...

关于php - PHP Strtotime -1个月-2个月,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1211824/

10-12 14:26