请参阅php中的评论。
卡车车队ETA计算器
以公里为单位的距离:城市a到城市b
$dist_city_a_city_b = 475;
加载/准备时间
$turnaround = 45;
出发时间
$departtime = date('Y-m-d H:i:s');
echo "Distance: $dist_city_a_city_b Kilometers<br>";
$distM = $dist_city_a_city_b*1000;
echo "Distance: $distM in meters<br>";
以每小时公里为单位的速度常数
$speed = 80/3.6;
echo "Speed: $speed converted to meters/second<br>";
$eta_1 = $distM/$speed;
echo "Distance / Speed: $eta_1<br>";
$eta = $eta_1/60;
echo "All in minutes = $eta<br>";
$arivaltime = $eta + $turnaround;
echo "Arriveal in minutes including turnaround: $arivaltime<br>";
echo "Depart Time: ".$departtime."<br>";
以下是计算后未正确显示日期的问题 需要下面的代码以适当的格式显示ETA将计算的旅行时间添加到出发时间,即356.25分钟,这意味着如果在中午12:00移动,那么它应该显示相同的日期和接近18:00的时间,并且如果23:00那么它应该移动到第二天的日期和时间,这将是05:00
echo "Arrival Time: " . date('Y-m-d H:i:s', strtotime($arivaltime, strtotime($departtime))) . " (ETA)<br>";
其余代码将是mysql表的发布
输出:
Distance: 475 Kilometers Distance: 475000 in meters Speed: 22.222222222222 converted to meters/second Distance / Speed: 21375 All in minutes = 356.25 Arriveal in minutes including turnaround: 401.25 Depart Time: 2015-05-21 23:53:03 Arrival Time: 1970-01-01 04:00:00 (ETA)
谢谢大家
SamimiIT
答案 0 :(得分:1)
选择出发时间,以秒为单位添加旅行时间,然后格式化:
echo "Arrival Time: " . date('Y-m-d H:i:s', strtotime($departtime) + $arivaltime * 60) . " (ETA)<br>";
我会重命名许多变量以使其更有意义。
$eta_1 -> $travel_seconds
$arivaltime -> $travel_minutes
答案 1 :(得分:0)
您实际上是在尝试从单个数字中获取日期。试试这个:
$arrival = strtotime($departtime) + ($arivaltime * 60);
echo "Arrival Time: " . date('Y-m-d H:i:s', $arrival) . " (ETA)<br>";