2016-01-23 83 views
0

我想更新一个unix时间戳并添加x个月。更新一个unix时间戳php(strtotime)

这是我使用1456256866

strtotime("+1 month") 

我想accieve什么是时间戳:

$time = '1456256866'; 
    //update $time with x months something like 
$time("+5 month"); 

有人可以把我在正确的方向?

,不胜感谢

回答

1

对于这样的操作,你应该使用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

+1

谢谢, 这已经解决了我的问题。 我不知道Datetime类 – notify

0

你可以做类似下面。函数strtotime需要第二个参数。

$time = 1456256866; 
$time = strtotime('+5 month', $time);