如何使用源时间和目的地时间计算旅行时间? [英] how to calculate travel time using source and destination times?
问题描述
出发地的出发时间是18:25
,目的地的到达时间是05:20
所以
Departure_Time at source is 18:25
and Arrival_Time at destination is 05:20
so
tt2.Arrival_Time -tt1.Departure_Time As Travel_Time
给出 -130500
而不是 10:55H
如何实现?任何帮助都会得到认可..非常感谢.!!
gives -130500
instead 10:55H
how to achive this? any help will be appretiated..many thanks.!!
编辑-目的地时间是第二天..
edit- destination time is of second day..
推荐答案
我给你写了一个代码,你可以修改出发和到达之间的天数差异.但是但是这个代码只是并且只针对一个时区.如果你在不同的时区有不同的时间那就不一样了!
I wrote a code for you that you can modify the difference of days between departure and arrival.But but but this code is only and only for a single time zone.If you have different times in different time zones that's different!
<?php
/**/
$Departure_Time='05:20';//Set Departure time
$Arrival_Time='18:30';//Set Arrival time
$dayDifference=0;//You can modify this
/**/
$a=strtotime($Departure_Time);
$b=strtotime($Arrival_Time.' + '.($dayDifference*24).' Hours');
$interval = ($b - $a) / 60;
$traveltime=date("i:s",$interval);
echo $traveltime;
?>
而且我真的不知道为什么我用 i:s 来表示小时和分钟!
And I really don't have any ideas why did I use i:s for hour and minute!
但无论如何它都有效!
如果您对代码有任何疑问,请告诉我:)
Tell me if you have any problem with the code :)
这篇关于如何使用源时间和目的地时间计算旅行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!