时间差异在两个日期之间的分钟 [英] Time diff in minutes between 2 dates
本文介绍了时间差异在两个日期之间的分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
得到这个工作在php 5.3
Got this working on php 5.3
$datetime1 = new DateTime("2011-10-10 10:00:00");
$datetime2 = new DateTime("2011-10-10 10:45:00");
$interval = $datetime1->diff($datetime2);
$hours = $interval->format('%h');
$minutes = $interval->format('%i');
echo 'Diff. in minutes is: '.($hours * 60 + $minutes);
我如何使其在php 5.2上工作?有没有相应的功能可用?
How can i make it work on php 5.2 ? are there any equivalent functions available??
得到它的工作
$date1 = "2011-10-10 10:00:00";
$date2 = "2011-10-10 10:11:00";
echo round((strtotime($date2) - strtotime($date1)) /60);
推荐答案
而不是 DateTime
您可以使用
strtotime
和 date
:
$datetime1 = strtotime("2011-10-10 10:00:00");
$datetime2 = strtotime("2011-10-10 10:45:00");
$interval = abs($datetime2 - $datetime1);
$minutes = round($interval / 60);
echo 'Diff. in minutes is: '.$minutes;
这篇关于时间差异在两个日期之间的分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文