返回当前日期加7天

时间:2012-08-16 13:38:57

标签: php date

我正在尝试获取当前日期加7天才能显示。

示例:今天是2012年8月16日,所以这个php片段将在2012年8月23日输出。

   $date = strtotime($date);
   $date = strtotime("+7 day", $date);
   echo date('M d, Y', $date);

现在,我得到了:1970年1月8日。我错过了什么?

10 个答案:

答案 0 :(得分:126)

strtotime会自动使用当前的unix时间戳来将字符串注释作为基础。

只是做:

$date = strtotime("+7 day");
echo date('M d, Y', $date);

为未来访问者添加了信息:如果您需要将时间戳传递给该功能,则以下内容将有效。

这将从昨天开始计算7 days

$timestamp = time()-86400;

$date = strtotime("+7 day", $timestamp);
echo date('M d, Y', $date);

答案 1 :(得分:9)

$date = new DateTime(date("Y-m-d"));
$date->modify('+7 day');
$tomorrowDATE = $date->format('Y-m-d');

答案 2 :(得分:6)

如果从现在起7天后你正在寻找,只需加上:

$date = strtotime("+7 day", time());
echo date('M d, Y', $date);

答案 3 :(得分:5)

$now = date('Y-m-d');
$start_date = strtotime($now);
$end_date = strtotime("+7 day", $start_date);
echo date('Y-m-d', $start_date) . '  + 7 days =  ' . date('Y-m-d', $end_date);

答案 4 :(得分:4)

<?php
print date('M d, Y', strtotime('+7 days') );

答案 5 :(得分:3)

您没有使用 time()函数返回自Unix Epoch(1970年1月1日00:00:00 GMT)以来的秒数测量的当前时间。 像这样使用:

$date = strtotime(time());
$date = strtotime("+7 day", $date);
echo date('M d, Y', $date);

答案 6 :(得分:1)

此代码适用于我:

public class SoftwareTest extends Config {

private Log log = LogFactory.getLog(SoftwareTest.class);

@BeforeClass(alwaysRun = true)
public void setup() throws InterruptedException {

    softwarepage = new SoftwarePage(driver);

}

答案 7 :(得分:1)

$date = strtotime("+7 day", strtotime("M d, Y"));
$date =  date('j M, Y', $date);

这也可以

答案 8 :(得分:0)

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

答案 9 :(得分:0)

在这里,您可以使用strtotime()来做到这一点,

<?php
    $date = strtotime("3 October 2005");
    $d = strtotime("+7 day", $date);
    echo "Created date is " . date("Y-m-d h:i:sa", $d) . "<br>";
?>
相关问题