【发布时间】:2012-08-03 13:15:51
【问题描述】:
评论是我看到的输出。救命!
echo date("Y-m-t", strtotime("2012-07-31 -1 month")); //2012-07-31
echo date("Y-m-t", strtotime("2012-07-31 -2 month")); //2012-05-31
7 月有 31 天,所以不能按 8 月 1 日来处理,对吧?即使是这样,第二行也应该起作用。对吧?!
谢谢!
【问题讨论】:
-
您可能在夏令时导致代码中出现错误 - 或者今年是闰年 - 其中一个 PHP 函数可能存在一些不完善的计算。跨度>
-
参见here .. 注意:不建议将此函数用于数学运算。最好在 PHP 5.3 及更高版本中使用 DateTime::add() 和 DateTime::sub(),或者在 PHP 5.2 中使用 DateTime::modify()。
标签: php codeigniter date