PHP microtime() Function
In this chapter you will learn:
- Definition for PHP microtime() Function
- Syntax for PHP microtime() Function
- Parameter for PHP microtime() Function
- Return value for PHP microtime() Function
- Example - Return the current Unix timestamp with microseconds
Definition
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.
Syntax
mixed microtime ( [bool float_output ] )
Parameter
PHP microtime() Function has the following parameter.
- float_output - Optional. TRUE specifies that the function should return a float, instead of a string. Default is FALSE
Return
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.
Example
Return the current Unix timestamp with microseconds:
<?php
echo(microtime());
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mktime() Function
- Syntax for PHP mktime() Function
- Parameter for PHP mktime() Function
- Return value for PHP mktime() Function
- Example - use PHP mktime() Function to create an integer Unix timestamp