1

如何在时间戳中添加天数并回显时间。我尝试并能够为其添加天数,但是当 echo 显示为否时。

$timestamp = strtotime('+7 days', $row['sdate']);

这段代码是否正确。

谢谢

4

2 回答 2

3

它应该像

$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);
于 2013-08-01T13:21:43.090 回答
0

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

http://php.net/manual/en/function.date.php

于 2013-08-01T13:23:51.507 回答