Skip to content

Instantly share code, notes, and snippets.

@cezarpopa
Created December 8, 2020 16:35
Show Gist options
  • Save cezarpopa/3080e36c19b7f8ac6e445c71d3e2309b to your computer and use it in GitHub Desktop.
Save cezarpopa/3080e36c19b7f8ac6e445c71d3e2309b to your computer and use it in GitHub Desktop.
microtime to seconds
<?php
function format_period($seconds_input)
{
$hours = (int)($minutes = (int)($seconds = (int)($milliseconds = (int)($seconds_input * 1000)) / 1000) / 60) / 60;
return $hours . ':' . ($minutes % 60) . ':' . ($seconds % 60) . (($milliseconds === 0) ? '' : '.' . rtrim(
$milliseconds % 1000,
'0'
));
}
$startTime = microtime(true);
//whatever happens in between
echo '<br/>Total execution time in seconds: ' . format_period((microtime(true) - $startTime));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment