How to get microtime in php?
❮ PHP Date/Time Reference Show ExampleReturn the current Unix timestamp with microseconds: echo(microtime()); Try it Yourself » Definition and UsageThe microtime() function returns the current Unix timestamp with microseconds. SyntaxParameter Values
Technical Details
❮ PHP Date/Time Reference (PHP 4, PHP 5, PHP 7, PHP 8) microtime — Return current Unix timestamp with microseconds Descriptionmicrotime(bool For performance measurements, using hrtime() is recommended. Parametersas_float If used and set to Return Values By default, microtime() returns a string in the form "msec sec", where If ExamplesExample #1 Timing script execution
"Did nothing in $time seconds\n"; Example #2 microtime() and
"Did nothing in $time seconds\n"; See Also
Short answer:64 bits platforms only!
[ If you are running 64 bits PHP then the constant Long answer:If you want an equilvalent function of The size of an integer in PHP can be 32 or 64 bits depending on platform. From http://php.net/manual/en/language.types.integer.php
If you have 64 bits integers then you may use the following function:
The second number is the seconds (integer) while the first one is the decimal part. The above function
then adds the decimal part multiplied by
Note that both Finally, that function is slightly more precise than
that with a ratio of 1:10 (approx.) returns 1 more millisecond than the correct result. This is due to the limited precision of the float type ( Even if it's beyond the scope of the question it's worth mentioning that if your platform supports 64 bits integers then you can also get the current time in microseconds without incurring in overflow. If fact That's the same value you get with
In other words, a signed 64 bits integer have room to store a timespan of over 200,000 years measured in microseconds. You may have then
How to use microtime in PHP?PHP microtime() function returns the current Unix timestamp. By default this returns a string value in the form msec sec. If you pass the boolean value true as a parameter to this method, it returns the current time in seconds since the Unix epoch accurate to the nearest microsecond.
What is microtime?Definition of microtime
: a very short interval of time (as 0.01 millionth of a second) microtime photography.
Is microtime in seconds?By default, microtime() returns a string in the form "msec sec", where sec is the number of seconds since the Unix epoch (0:00:00 January 1,1970 GMT), and msec measures microseconds that have elapsed since sec and is also expressed in seconds as a decimal fraction.
How to get time in ms in PHP?How to get current time in milliseconds in PHP?. $milliseconds = round(microtime(true) * 1000); ... . var_dump(microtime()); // string(21) "0.89115400 1283846202" var_dump(microtime(true)); // float(1283846202.89). |