php的日期差异在天? [英] Date Difference in php on days?
本文介绍了php的日期差异在天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ date1 ='2009-11-12 12:09:08'
$ date2 ='2009-12-01 08:20:11'
然后做一个计算,$ date2减$ date1
我读了php.net文档,但没有运气。有一个快速的方法吗?
解决方案
strtotime将您的日期字符串转换为unix时间戳。 (从unix纪元开始的秒数。
$ ts1 = strtotime($ date1);
$ ts2 = strtotime date2);
$ seconds_diff = $ ts2 - $ ts1;
Is there a quick way to calculate date difference in php? For example:
$date1 = '2009-11-12 12:09:08';
$date2 = '2009-12-01 08:20:11';
And then do a calculation, $date2 minus $date1
I read php.net documentation, but no luck. Is there a quick way to do it?
解决方案
strtotime will convert your date string to a unix time stamp. (seconds since the unix epoch.
$ts1 = strtotime($date1);
$ts2 = strtotime($date2);
$seconds_diff = $ts2 - $ts1;
这篇关于php的日期差异在天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文