如何在时间戳中添加天数并回显时间。我尝试并能够为其添加天数,但是当 echo 显示为否时。
$timestamp = strtotime('+7 days', $row['sdate']);
这段代码是否正确。
谢谢
它应该像
$date = strtotime($row['sdate']);
$date = strtotime("+7 day", $date);
echo date('Y-m-d H:i:s',$date);
或者你也可以试试
$date = strtotime('+7 days', strtotime($row['sdate']) );
echo date('Y-m-d',$date);
Strtotime 函数需要 unix 时间戳,所以你需要转换你的时间(我希望是正常的日期时间)?
strtotime('+7 days', strtotime($row['sdate']) );
然后,如果您想再次将其格式化为日期时间,您可以这样做:
$timestamp = strtotime('+7 days', strtotime($row['sdate']) );
echo date("Y-m-d H:i:s", $timestamp);
您可以在 php 的手册中阅读更多关于 strtotime 和 date 的信息。 http://php.net/manual/en/function.strtotime.php