现在,时间戳和时间()之间的差异大约是一个小时。
我有一个奇怪的问题,如果我回应分钟,我得到一个像4
这样的低数字是不正确的。
如果我回应小时数,我会获得正确的金额1
以及获得0
天数。我不确定为什么分钟没有正确显示。
$ticket_resolve = '1496264673';
$date1_find_days_resolve = new DateTime(date("Y-m-dTH:i:s",time()));
$date2_find_days_resolve = new DateTime(date("Y-m-dTH:i:s",$ticket_resolve));
$diff_resolve = $date2_find_days_resolve->diff($date1_find_days_resolve);
$mins_first_resolve = $diff_resolve->format('%i');
$hours_first_resolve = $diff_resolve->format('%h');
$days_first_resolve = $diff_resolve->format('%a');
答案 0 :(得分:2)
您需要将小时转换为分钟以获得所需的输出,如下所示: -
<?php
$ticket_resolve = '1496264673';
$date1_find_days_resolve = new DateTime(date("Y-m-dTH:i:s",time()));
$date2_find_days_resolve = new DateTime(date("Y-m-dTH:i:s",$ticket_resolve));
$diff_resolve = $date2_find_days_resolve->diff($date1_find_days_resolve);
$mins_first_resolve = $diff_resolve->format('%i');
$hours_first_resolve = $diff_resolve->format('%h');
$days_first_resolve = $diff_resolve->format('%a');
echo $total_minutes = $hours_first_resolve*60+$mins_first_resolve;
输出: - https://eval.in/809143
注意: - 要转换天数,您也可以执行$days_first_resolve*24*60