我有两个约会
$date1 = "2014-02-11 04:04:26 AM"
$date2 = "2014-02-11 05:36:56 AM"
我想计算差异并将其显示如下
1 hour 32 minutes
答案 0 :(得分:17)
利用DateTime
类
DateTime::diff
<?php
$datetime1 = new DateTime('2014-02-11 04:04:26 AM');
$datetime2 = new DateTime('2014-02-11 05:36:56 AM');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%h')." Hours ".$interval->format('%i')." Minutes";
<强> OUTPUT :
强>
1 Hours 32 Minutes
答案 1 :(得分:7)
如果不希望以复杂的方式执行此操作,只需将两个日期转换为时间戳即可... 像这样的东西
$dateDiff = intval((strtotime($date1)-strtotime($date2))/60);
$hours = intval($dateDiff/60);
$minutes = $dateDiff%60;
然后你去......
谢谢...