microtime
Description
The microtime of Date / Time for PHP return current Unix timestamp with microseconds.
Syntax
microtime( bool $as_float = false ): string|float
Parameters
as_float
If used and set to true, microtime() will return a float instead of a string, as described in the return values section below.
Return
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.
If as_float is set to true, then microtime() returns a float, which represents the current time in seconds since the Unix epoch accurate to the nearest microsecond.
Examples
1 · void
<? $return = microtime(); echo $return;
0.09912900 1747207920
2 · as_float
<? $as_float = true; $return = microtime($as_float); echo $return;
1747207920.3205
3 · explode
<? $return = microtime(); list($microseconds, $seconds) = explode(" ", $return); $time = $seconds + $microseconds; echo $seconds . PHP_EOL . $microseconds . PHP_EOL . PHP_EOL . $time;
1747207920 0.49810000 1747207920.4981
4 · usleep · microtime · void
<? function myfunction() { $return = microtime(); list($microseconds, $seconds) = explode(" ", $return); $time = $seconds + $microseconds; return $time; } $time_start = myfunction(); usleep(1000); $time_end = myfunction(); $time = $time_end - $time_start; echo $time;
0.0010881423950195
5 · usleep · microtime · as_float
<? $as_float = true; $time_start = microtime($as_float); usleep(1000); $time_end = microtime($as_float); $time = $time_end - $time_start; echo $time;
0.0025389194488525
6 · usleep · REQUEST_TIME_FLOAT
<? $as_float = true; usleep(1000); $time_end = microtime($as_float); $time = $time_end - $_SERVER["REQUEST_TIME_FLOAT"]; echo $time;
0.0013778209686279
Links
Date / Time
- checkdate
- date
- date_add
- date_create
- date_create_from_format
- date_create_immutable
- date_create_immutable_from_format
- date_date_set
- date_default_timezone_get
- date_default_timezone_set
- date_diff
- date_format
- date_get_last_errors
- date_interval_create_from_date_string
- date_interval_format
- date_isodate_set
- date_modify
- date_offset_get
- date_parse
- date_parse_from_format
- date_sub
- date_sun_info
- date_sunrise
- date_sunset
- date_time_set
- date_timestamp_get
- date_timestamp_set
- date_timezone_get
- date_timezone_set
- getdate
- gettimeofday
- gmdate
- gmmktime
- gmstrftime
- idate
- localtime
- mktime
- strftime
- strptime
- strtotime
- time
- timezone_abbreviations_list
- timezone_identifiers_list
- timezone_location_get
- timezone_name_from_abbr
- timezone_name_get
- timezone_offset_get
- timezone_open
- timezone_transitions_get
- timezone_version_get