Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP microtime() Function.
PHP microtime() function returns current Unix timestamp with microseconds. By default, this function returns a string value which contains microseconds and seconds which is separated by space (msec sec).
PHP microtime() function returns current Unix timestamp with microseconds. By default, this function returns a string value which contains microseconds and seconds which is separated by space (msec sec).
Syntax
Following below is the syntax to use this function -
microtime($get_as_float)
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | get_as_float(Optional) This is a boolean value which is used to specify whether the result should be a floating point value or not. If you pass the boolean value true as a parameter, this function returns result as floating point value. |
Return Value
This PHP 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 function, then it returns the current time in seconds since Unix epoch which is accurate to the nearest microseconds.
PHP Version
This function was first introduced as part of the core PHP v 4 and, it works with all the later versions.
Example1
Following example illustrates the usage of the PHP microtime() function -
<?php $time = microtime(); print($time); ?>
Output
When the above code is executed, it will produce the following result -
0.01174200 1606064533
Example2
Let us try to set the get_as_float value to true -
<?php $time = gettimeofday(true); print_r($time); ?>
Output
When the above code is executed, it will produce the following result -
1606064723.7694
Example3
Try the following example -
<?php $time_start = microtime(true); usleep(100); $time_end = microtime(true); $time = $time_end - $time_start; echo "Did nothing in $time seconds\n"; ?>
Output
When the above code is executed, it will produce the following result -
Did nothing in 0.00095605850219727 seconds
READ: PHP | idate() Function
Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP mktime() Function.
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.