返回当前日期加上7天 [英] Return current date plus 7 days
本文介绍了返回当前日期加上7天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将当前日期加上7天显示。
I'm Trying to get the current date plus 7 days to display.
示例:今天是2012年8月16日,所以这个PHP代码段将输出2012年8月23日。
Example: Today is August 16, 2012, so this php snippet would output August 23, 2012.
$date = strtotime($date);
$date = strtotime("+7 day", $date);
echo date('M d, Y', $date);
现在,我得到:1970年1月8日,我缺少什么?
Right now, I'm getting: Jan 08, 1970. What am I missing?
推荐答案
strtotime
将自动使用当前的unix时间戳来将字符串注释作为
strtotime
will automatically use the current unix timestamp to base your string annotation off of.
只需执行
$date = strtotime("+7 day");
echo date('M d, Y', $date);
为未来访问者添加信息:如果您需要传递时间戳该功能将在下文中运行。
Added Info For Future Visitors: If you need to pass a timestamp to the function, the below will work.
这将从昨天开始计算 7天
$timestamp = time()-86400;
$date = strtotime("+7 day", $timestamp);
echo date('M d, Y', $date);
这篇关于返回当前日期加上7天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文