开发者

Subtracting a timestamp from present-time in PHP, express in minutes

I have a variable $minutes that expresses a poi开发者_如何学JAVAnt in time like this: 2011-08-31 21:02:15

How could I subtract it from the present time, and express the difference in minutes?


$minutes = (int)((time()-strtotime($minutes))/60);

Example Here


You could use the DateTime and DateInterval classes.

$now = new DateTime();
$then = new DateTime("2011-08-31 21:02:15");
$minutes = $now->diff($then)->i;

If you have a UNIX timestamp instead of a string, you can do this instead:

$now = new DateTime();
$then = new DateTime();
$then->setTimestamp(myTimestamp);
$minutes = $now->diff($then)->i;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜