Last active
December 14, 2015 01:09
-
-
Save Dynom/5003750 to your computer and use it in GitHub Desktop.
Obtaining various fractions of time, using the microtime() function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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