Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用strotime和date将时间添加到日期_Php_Date_Strtotime - Fatal编程技术网

Php 使用strotime和date将时间添加到日期

Php 使用strotime和date将时间添加到日期,php,date,strtotime,Php,Date,Strtotime,即使在阅读了关于堆栈溢出的永无休止的问题之后,我也很难理解strotime date('Y-m-d',strtotime("+3 months",date('Y-m-d'))) 为什么不返回2013-10-09(假设今天的日期是2013-07-09) 相反,它在PHP默认日期后3个月返回1970-03-31 date('Y-m-d',strtotime("+3 months", time())) 甚至 date('Y-m-d',strtotime("+3 months")) PS:如果使用

即使在阅读了关于堆栈溢出的永无休止的问题之后,我也很难理解strotime

date('Y-m-d',strtotime("+3 months",date('Y-m-d')))
为什么不返回
2013-10-09
(假设今天的日期是
2013-07-09

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

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

date('Y-m-d',strtotime("+3 months"))
PS:如果使用
error\u reporting
级别,包括
E\u NOTICE
并检查日志,您可以自己找到它


实际上,在开发服务器上启用
display\u errors
error\u reporting
至少是
E\u ALL
是一个好主意。作为一名开发人员,你想成为第一个看到错误的人,不是吗?

——日期是用来格式化时间戳的。如果您想获取当前时间戳,请使用
time()
。因此,我将使用字符串“+3个月”并以日期('Y-m-d')格式添加到time()……正确吗?@Hydra IO:您将使用
time()
向其添加
+3个月
,并使用
日期
正确地格式化结果时间戳,顺便说一句,你可以用单数和复数表示句号,所以“+3个月”也可以。非常感谢你,一旦讨厌的10分钟限制到期,我可以标记为solved=D