2008-11-01 94 views
0

该事件返回格式为“Sat Oct 25 21:55:29 +0000 2008”的标准化时间戳 如何将此值与PHP中的当前时间进行比较,以便以“It It”形式给出结果已经15分钟了!“或“已经三天了!”另外,我如何获得当前时间?我怎样才能找到事件发生以来的时间?

回答

6

首先使用strtotime()该字符串转换为UNIX时间戳:

$event_time = strtotime('Sat Oct 25 21:55:29 +0000 2008'); 

然后获得当前的UNIX时间戳使用time()

$current_time = time(); 

然后让这些时间戳之间的秒数:

$difference = $current_time - $event_time; 

最后用分割室温的秒数到几天或几小时或任何数量:

​​3210

有关计算相对时间的更多信息,请参见How do I calculate relative time?

+0

打我吧。 (ps:gratz on 5000 rep) – nickf 2008-11-01 06:44:23