我有一个函数可以计算参数基础上的分钟
function calculate_time_date($argmnt1, $argmnt2)
{
$to_time = strtotime($argmnt2);
$from_time = strtotime($argmnt1);
return round(abs($to_time - $from_time) / 60,2);
}
echo calculate_time_date('13/05/2017 16:00', '13/05/2017 19:30');
echo '<br>';
echo calculate_time_date('12/05/2017 16:00', '12/05/2017 19:30');`
现在这段代码给出了结果0
和210
但是两个结果都需要 210,你能帮我什么吗?
如果你忽略日期,你只会得到正确的分钟数。
function calculate_time_date($argmnt1, $argmnt2)
{
$to_time = strtotime(substr($argmnt2, -5));
$from_time = strtotime(substr($argmnt1, -5));
return round(abs($to_time - $from_time) / 60,2);
}
echo calculate_time_date('13/05/2017 16:00', '13/05/2017 19:30');
echo '<br>';
echo calculate_time_date('12/05/2017 16:00', '12/05/2017 19:30');
我将格式更改为 13-05-2017 16:00 它工作正常
function calculate_time_date($argmnt1, $argmnt2)
{
$to_time = strtotime($argmnt2);
$from_time = strtotime($argmnt1);
return round(abs($to_time - $from_time) / 60,2);
}
echo calculate_time_date('13-05-2017 16:00', '13-05-2017 19:30');
echo '<br>';
echo calculate_time_date('12-05-2017 16:00', '12-05-2017 19:30');
?>