开发者

add time for timestamp

Wha开发者_JS百科t is the best method for adding time to a timestamp? I have in a database

2011-10-09 10:29:23

and I would like add to this 20 days. How can I do that? I need an example for:

  1. 20 hours
  2. 20 days


You can use Date::add like this:

<?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

Use PHP's strtotime function like:

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


Another method that works well with Frame is

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

where the number at the end is the old php method (*days*hours*mins*secs)


I recommend you to use unix_timestamps, with these you're able to work faster, and if the times were to be displayed to the user, you can use gmdate().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜