使用PHP计算通过时间 [英] Calculate passed time with PHP
问题描述
我得到了这样的日期之间的时差:
I got the time difference between dates like this :
$time1 = "2013-02-25 12:00:00";
$time2 = "2013-01-01 12:00:00";
$tdiff = strtotime($time1) - strtotime($time2);
我想从 $ tdiff $ c中提取日期,小时和分钟$ c>。输出应为:
35天6小时14分钟
我真的进行了搜索并尝试自己做某事。但是我无法获得真正的价值。
I really searched and try to do something by myself. But I can't get true value.
----编辑----
我可以找到日期差。我要从计算的时间中提取天,小时,分钟...
---- EDIT ---- I can found date diff. I want extract days, hours, minutes from calculated time...
----编辑2 ----
这是我完整的mysql代码
---- EDIT 2 ---- Here is my complete mysql code
select (
select avg(UNIX_TIMESTAMP(tarih)) from table1
where action in (6) and who = '".$user."' and dates between '".$date1."' and '".$date."'
) - (
select avg(UNIX_TIMESTAMP(tarih_saat)) from table2
where action in (6) and active = 1 and dates between '".$date1."' and '".$date2."
)
此查询向我返回时间的真实值。此查询对我来说正常工作。结果类似于: 215922
。 UNIX_TIMESTAPM的结果类型。因此,我想了解此时间戳记中的天数,小时数和分钟数。
This query returns to me true value of time. This query is working correctly for me. Result is like : 215922
. result type of UNIX_TIMESTAPM. So I want to learn how many days, hours and minutes in this timestamp.
推荐答案
PHP有一个DateInterval类,可以这样使用:
PHP has a DateInterval class which can be used like so:
$date1 = new DateTime('2013-02-25 12:00:00');
$date2 = new DateTime('2013-01-01 12:00:00');
$diff = $date2->diff($date1); // Get DateInterval Object
echo $diff->format('%d Day and %h hours and %m minutes');
这篇关于使用PHP计算通过时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!