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.55540200 1739564784
2 · as_float
<? $as_float = true; $return = microtime($as_float); echo $return;
1739564784.6112
3
<? list($msec, $sec) = explode(" ", microtime()); $time = $sec + $msec; echo $time;
1739564784.6655
4
<? function microtime_as_float() { list($msec, $sec) = explode(" ", microtime()); $time = $sec + $msec; return $time; } $time_start = microtime_as_float(); usleep(100); $time_end = microtime_as_float(); $time = $time_end - $time_start; echo "$time seconds";
0.00018692016601562 seconds
5
<? $as_float = true; $time_start = microtime($as_float); usleep(100); $time_end = microtime($as_float); $time = $time_end - $time_start; echo "$time seconds";
0.00015711784362793 seconds
6
<? // REQUEST_TIME_FLOAT contains the timestamp of the start of the request with microsecond precision usleep(100); $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; echo "$time seconds";
0.00017094612121582 seconds
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