我只是尝试从当前日期 08/29/2015 @ 11:19am (UTC)
分别减去 6 个月和 5 个月,得到了相同的结果
这是代码示例:
date("M, Y", strtotime("-5 months")) // returns Mar, 2015
date("M, Y", strtotime("-6 months")) // returns Mar, 2015
是因为夏令时吗?我认为不。
最佳答案
date("M, Y", strtotime("-6 months"))
也简单地返回 Mar, 2015
因为今年没有 29.February。所以需要下个月,也就是三月。
要解决这个问题,只需从每个月的第一天开始,例如
echo date("M, Y", strtotime("-6 months", strtotime(date('Y-m-01'))));
//^^^^^^^^^^^^^^^^^^^^^^^^^ First day of month
关于php - 从当前日期减去月份返回意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32285483/