Skip to content

Instantly share code, notes, and snippets.

@garvin
Last active February 8, 2018 17:46
Show Gist options
  • Save garvin/9da96f6ef1e82a5399d0339091f7b8fe to your computer and use it in GitHub Desktop.
Save garvin/9da96f6ef1e82a5399d0339091f7b8fe to your computer and use it in GitHub Desktop.
Function to generate a timestamp (in # of milliseconds)
/**
* Generate a timestamp (in # of milliseconds)
*
* @return string
*/
function millitime() {
$microtime = microtime();
$comps = explode(' ', $microtime);
// Note: Using a string here to prevent loss of precision
// in case of "overflow" (PHP converts it to a double)
return sprintf('%d%03d', $comps[1], $comps[0] * 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment