为时间戳添加时间

问题描述:

将时间添加到时间戳的最佳方法是什么? 我有一个数据库为时间戳添加时间

2011-10-09 10点29分23秒

,我想加入到这个20天。我怎样才能做到这一点? 我需要一个例子:

  1. 20小时
  2. 20天
+1

请点你为什么不能够找到解决你的问题[*上类似问题的大量问如何添加时间到日期](http://*.com/search?q=add+time+php)。此外,为什么这个标记的doctine和symfony的问题没有提到这些问题? – Gordon

您可以使用Date::add这样:

<?php 
$date = new DateTime('2011-10-09 10:29:23'); 
$date->add(new DateInterval('P20D')); //use PT20H for 20 hours 
echo $date->format('Y-m-d H:i:s'); 
?> 

http://www.php.net/manual/en/function.strtotime.php

使用PHP的像的strtotime功能:

$newtimestamp = strtotime("+20 days", $yourtimestamp); 

我建议您使用unix_timestamps,这样您可以更快地工作,并且如果将时间显示给用户,则可以使用gmdate()。

与框架行之有效的另一种方法是

$time = date('Y-m-d H:i:s', time($foo->time_stamp + (24*60*60))); 

在那里到底有多少是旧的PHP方法(*days*hours*mins*secs)