问题
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
gives -130500 instead 10:55H how to achive this? any help will be appretiated..many thanks.!!
edit- destination time is of second day..
回答1:
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;
?>
And I really don't have any ideas why did I use i:s for hour and minute!
But anyway it works!
Tell me if you have any problem with the code :)
来源:https://stackoverflow.com/questions/51386237/how-to-calculate-travel-time-using-source-and-destination-times