更新 unix 时间戳 php (strtotime)
Update a unix timestamp php (strtotime)
我想更新 unix 时间戳并添加 x 个月。
这是我使用的时间戳 1456256866
strtotime("+1 month")
我想要实现的是:
$time = '1456256866';
//update $time with x months something like
$time("+5 month");
有人能告诉我正确的方向吗?
非常感谢
对于这样的操作你应该使用Datetime
class,尤其是Add
方法:
$date = new DateTime('@1456256866');
$date->add(new DateInterval('P5M'));
echo $date->format('Y-m-d') . "\n";
您可以执行如下操作。函数 strtotime
接受第二个参数。
$time = 1456256866;
$time = strtotime('+5 month', $time);
我想更新 unix 时间戳并添加 x 个月。
这是我使用的时间戳 1456256866
strtotime("+1 month")
我想要实现的是:
$time = '1456256866';
//update $time with x months something like
$time("+5 month");
有人能告诉我正确的方向吗?
非常感谢
对于这样的操作你应该使用Datetime
class,尤其是Add
方法:
$date = new DateTime('@1456256866');
$date->add(new DateInterval('P5M'));
echo $date->format('Y-m-d') . "\n";
您可以执行如下操作。函数 strtotime
接受第二个参数。
$time = 1456256866;
$time = strtotime('+5 month', $time);