我正在尝试获取当前日期加上 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 日。我错过了什么?
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);
$date = new DateTime(date("Y-m-d"));
$date->modify('+7 day');
$tomorrowDATE = $date->format('Y-m-d');
如果您要查找的是 7 天后,只需输入:
$date = strtotime("+7 day", time());
echo date('M d, Y', $date);
$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);
<?php
print date('M d, Y', strtotime('+7 days') );
您没有使用time()函数返回以自 Unix 纪元(格林威治标准时间 1970 年 1 月 1 日 00:00:00)以来的秒数测量的当前时间。像这样使用:
$date = strtotime(time());
$date = strtotime("+7 day", $date);
echo date('M d, Y', $date);
这段代码对我有用:
<?php
$date = "21.12.2015";
$newDate = date("d.m.Y",strtotime($date."+2 day"));
echo $newDate; // print 23.12.2015
?>
$date = strtotime("+7 day", strtotime("M d, Y"));
$date = date('j M, Y', $date);
这也可以
echo date('d-m-Y', strtotime('+7 days'));
这是您可以使用的方法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>";
?>