作者:晴可倾 | 来源:互联网 | 2016-03-16 00:21
通过strtotime可以把任意时间格式转换为unix时间戳,从而相减得到两个时间相差的秒数
[php]
$time1 = '2008-08-02 14:01:11';
$time2 = '2008-08-02 14:02:11';
echo strtotime($time1) - strtotime($time2);
?>
[/php]
strtotime -- 将任何英文文本的日期时间描述解析为 Unix 时间戳
说明
int strtotime ( string time [, int now] )
本函数预期接受一个包含美国英语日期格式的字符串并尝试将其解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数),其值相对于 now 参数给出的时间,如果没有提供此参数则用系统当前时间。