The microtime()
function returns current time.
When called without any parameters, this returns the current system time in seconds and
microseconds, ordered microseconds first.
For example: 0.12342123 1234123412.
mixed microtime ( [bool float_output ] )
PHP microtime() Function has the following parameter.
Returns the string "microsec sec" by default, where sec is the number of seconds since the Unix Epoch (0:00:00 January 1, 1970 GMT), and microsec is the microseconds part.
If the get_as_float parameter is set to TRUE, it returns a float to the nearest microsecond representing the current time in seconds since the Unix epoch.
Return the current Unix timestamp with microseconds:
<?php
echo(microtime());
?>
The code above generates the following result.
The following code shows how to use current Unix timestamp with microseconds in for loop.
<?php// w w w . j ava 2s . com
$startTime = microtime( true );
for ( $num = 1; microtime( true ) < $startTime + 0.0001; $num = $num * 2 ) {
echo "Current number: $num<br />";
}
echo "Out of time!";
?>
The code above generates the following result.