使用strtotime和日期来添加时间

时间:2013-07-10 03:28:53

标签: php date strtotime

即使在阅读关于主题堆栈溢出的永无止境的问题之后,我也非常难以理解strtotime ....

date('Y-m-d',strtotime("+3 months",date('Y-m-d')))

为什么不返回2013-10-09(今天的日期为2013-07-09

相反,它会在PHP默认日期之后3个月返回1970-03-31

1 个答案:

答案 0 :(得分:3)

因为strtotime()期望第二个参数是数字:

date('Y-m-d',strtotime("+3 months", time()))

甚至

date('Y-m-d',strtotime("+3 months"))

PS:如果使用包含error_reporting的{​​{1}}级别并检查了您的日志,则可以自行查找。

使用E_NOTICE至少display_errors的开发服务器启用error_reporting实际上是一个好主意。作为开发者,您希望成为第一个看到错误的人,不是吗?