PHP microtime() Function

In this chapter you will learn:

  1. Definition for PHP microtime() Function
  2. Syntax for PHP microtime() Function
  3. Parameter for PHP microtime() Function
  4. Return value for PHP microtime() Function
  5. 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:

  1. Definition for PHP mktime() Function
  2. Syntax for PHP mktime() Function
  3. Parameter for PHP mktime() Function
  4. Return value for PHP mktime() Function
  5. Example - use PHP mktime() Function to create an integer Unix timestamp
Home » PHP Tutorial » PHP Date Functions
PHP checkdate() Function
PHP date() Function
PHP date_add() Function
PHP date_create() Function
PHP date_create_from_format() Function
PHP date_date_set() Function
PHP date_default_timezone_get() Function
PHP date_default_timezone_set() Function
PHP date_diff() Function
PHP date_format() Function
PHP date_get_last_errors() Function
PHP date_interval_format() Function
PHP date_isodate_set() Function
PHP date_modify() Function
PHP date_offset_get() Function
PHP date_parse() Function
PHP date_parse_from_format() Function
PHP date_sub() Function
PHP date_sun_info() Function
PHP date_sunrise() Function
PHP date_sunset() Function
PHP date_time_set() Function
PHP date_timestamp_get() Function
PHP date_timestamp_set() Function
PHP date_timezone_get() Function
PHP date_timezone_set() Function
PHP getdate() Function
PHP gettimeofday() Function
PHP gmdate() Function
PHP gmmktime() Function
PHP gmstrftime() Function
PHP idate() Function
PHP localtime() Function
PHP microtime() Function
PHP mktime() Function
PHP strftime() Function
PHP strptime() Function
PHP strtotime() Function
PHP time() Function
PHP Timezones Constant
PHP timezone_abbreviations_list() Function
PHP timezone_identifiers_list() Function
PHP timezone_location_get() Function
PHP timezone_name_from_abbr() Function
PHP timezone_name_get() Function
PHP timezone_offset_get() Function
PHP timezone_open() Function
PHP timezone_version_get() Function