Skip to content

Instantly share code, notes, and snippets.

@Dynom
Last active December 14, 2015 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dynom/5003750 to your computer and use it in GitHub Desktop.
Save Dynom/5003750 to your computer and use it in GitHub Desktop.
Obtaining various fractions of time, using the microtime() function
<?php
$time = microtime(true);
$seconds = (int) $time;
$milliseconds = (int) ($time * 1000);
$microseconds = (int) ($time * 1000000);
$nanoseconds = (int) ($time * 1000000000);
echo "seconds : $seconds\n"
, "milliseconds: $milliseconds\n"
, "microseconds: $microseconds\n"
, "nanoseconds : $nanoseconds\n";
printf( "precision : %.0f", $time * 100000000000000000000000000000000000000000000000000000000000000000000);
/* A possible output:
seconds : 1361442556
milliseconds: 1361442556214
microseconds: 1361442556214164
nanoseconds : 1361442556214163968
precision : 136144255621416399633292374207085482089200595846391010716637640051976661106688
^^ --- Not sure how precise this is...
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment