添加日期的天数 [英] Add number of days to a date

查看:126
本文介绍了添加日期的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加到当前日期的天数:
我正在使用以下代码:

  $ i = 30; 
echo $ date = strtotime(date(Y-m-d,strtotime($ date))。+。$ i。days);

但是,没有获得正确的日期,我得到这个:
2592000



请建议。

解决方案

回覆日期('Ym-d',strtotime(+ 30天)); b>

  

strtotime


希望给出一个包含美国英文日期格式的字符串,并尝试将该格式解析为Unix时间戳(自1970年1月1日00:00以来的秒数:00 UTC),相对于现在给出的时间戳,或当前时间,如果现在不提供。


while 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");

But instead of getting proper date i am getting this: 2592000

Please suggest.

解决方案

This should be

echo date('Y-m-d', strtotime("+30 days"));

strtotime

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.

See the manual pages for

and their function signatures.

这篇关于添加日期的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆