Skip to content

Instantly share code, notes, and snippets.

@adeguntoro
Created October 31, 2019 21:34
Show Gist options
  • Save adeguntoro/c8b5027d5c052b7997660e475a97deb6 to your computer and use it in GitHub Desktop.
Save adeguntoro/c8b5027d5c052b7997660e475a97deb6 to your computer and use it in GitHub Desktop.
Menghitung Waktu kedatangan
<?php
$distance = 2000; //KM
$average_speed = 19; //KMh
$travel_time = $distance / $average_speed;
$departure_time = "2019-05-30 12:30:56";
$split = explode(".", $travel_time);
$hours = $split[0];
$minutes = ($travel_time - $split[0]) * 60;
$split_minutes = explode(".", $minutes );
$fix_minutes = $split_minutes[0];
$second = round(($minutes - $split_minutes[0]) * 60);
$date = new DateTime($departure_time);
$date->add(new DateInterval("PT".$split[0]."H".$fix_minutes."M".$second."S"));
echo $date->format("Y-m-d H:i:s");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment