向日期添加天数 [英] Add number of days to a date
问题描述
我想为当前日期添加天数:我正在使用以下代码:
I want to add number of days to current date: I am using following code:
$i=30;
echo $date = strtotime(date("Y-m-d", strtotime($date)) . " +".$i."days");
但我没有得到正确的日期,而是得到了这个:2592000
But instead of getting proper date i am getting this: 2592000
请提出建议.
推荐答案
这应该是
echo date('Y-m-d', strtotime("+30 days"));
strtotime
期望得到一个包含美国英语日期格式的字符串,并将尝试将该格式解析为 Unix 时间戳(自 1970 年 1 月 1 日 00:00:00 UTC 以来的秒数),相对于 now 给出的时间戳, 或者当前时间(如果没有提供 now ).
expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given in now, or the current time if now is not supplied.
while date
返回根据给定格式字符串格式化的字符串,使用给定的整数时间戳或当前时间(如果没有给定时间戳).
Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.
参见手册页
和它们的函数签名.
这篇关于向日期添加天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!