microtime
Description
The microtime of Date / Time for PHP return current Unix timestamp with microseconds.
Syntax
microtime(
bool $as_float = false
): string|floatParameters
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.99373900 1770997923
2 · void · explode
<?
$return = microtime();
[$microseconds, $seconds] = explode(" ", $return);
$time = $seconds + $microseconds;
echo $seconds, PHP_EOL,
$microseconds, PHP_EOL,
$time;
1770997924 0.49060100 1770997924.4906
3 · as_float
<? $as_float = true; $return = microtime($as_float); echo $return;
1770997925.8788
4 · usleep · microtime · void
<?
function myfunction()
{
$return = microtime();
[$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.0084140300750732
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.001835823059082
6 · usleep · REQUEST_TIME_FLOAT
<? $as_float = true; $time_start = $_SERVER["REQUEST_TIME_FLOAT"]; usleep(1000); $time_end = microtime($as_float); $time = $time_end - $time_start; echo $time;
0.0015461444854736
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