我想更新一个 unix 时间戳并添加 x 个月。
这是我使用的时间戳1456256866
strtotime("+1 month")
我想获得的是:
$time = '1456256866';
//update $time with x months something like
$time("+5 month");
有人能把我引向正确的方向吗?
非常感谢
你可以做下面这样的事情。 函数 strtotime
采用第二个参数。
$time = 1456256866;
$time = strtotime('+5 month', $time);
对于此类操作 您应该使用Datetime
类,尤其是Add
方法:
$date = new DateTime('@1456256866');
$date->add(new DateInterval('P5M'));
echo $date->format('Y-m-d') . "'n";
在此处查看更多内容: http://php.net/manual/pl/datetime.add.php