Home > Mobile >  Running Pace Calculation hours wrong calculated
Running Pace Calculation hours wrong calculated

Time:01-21

I would like to create a simple pace calculations table function in PHP.

When entering distance and time everything is calculated and created correctly, but the hours are displayed with 1. I tried to calculate the hours minus one ($formatedPace = date('H:i:s', strtotime($paceSum. '-1 hour'));) , but this did not work.

Where do I have my error here?

Current Output: enter image description here

Code:

// example //
$distance = 14;
$hours = 01;
$minutes = 10;
$seconds = 00;
// example //

$totalMinutes = ($hours * 3600)   ($minutes * 60)   $seconds;
$pace = $totalMinutes / $distance;

for($distanceCount = 1; $distanceCount <= $distance; $distanceCount  ) {
    $paceSum = $pace * $distanceCount;
    $formatedPace = date('H:i:s', $paceSum);

    echo '<tr>
            <td style="text-align: center">'.$distanceCount.' km</td>
            <td style="text-align: center">'.$formatedPace.'</td>
          </tr>';
}

CodePudding user response:

I think it's giving the correct output. I tried running your code and I got the following output.

Image of output for reference

CodePudding user response:

After a long search I found out that the time zone is responsible for the hour value always starting at one. To fix this, the default time zone must be set to UTC.

date_default_timezone_set('UTC');
  •  Tags:  
  • Related