在显示奇数的时间戳中添加天数


Adding days to a timestamp displaying odd number

我正在尝试将7天添加到存储在MySQL数据库中的时间戳中。

我正在使用strtotime:echo strtotime("+7 days",$result["datetime"]);

但是我得到这个结果606813

当我echo $result["dateimte"];时,我得到:2013-07-23 04:35:27

strtotime()希望第二个参数是Unix时间戳,而不是用MySQL DateTime格式格式化的字符串。

您首先需要将MySQL的结果转换为Unix时间戳,strtotime()应该完成您需要的操作:

strtotime($result["datetime"]."+7 days");

上述函数将输出:1375158927,相当于2013年7月30日星期二04:35:27。

下面将解释您应该做什么:

$d = strtotime("+7 days",strtotime("2013-07-23 04:35:27"));
echo date("d.m.Y H:i:s",$d);

试试这个代码-

$date=strtotime($result["datetime"]);
echo $newDate = date('Y-m-d h:i:s',strtotime('+7 days',$date));