Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

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.89864600 1720917960

2 · as_float

<?

$as_float = true;

$return = microtime($as_float);

echo $return;

?>
1720917960.9738

3

<?

list($msec, $sec) = explode(" ", microtime());
$time = $sec + $msec;

echo $time;

?>
1720917961.0525

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.00018906593322754 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.00015997886657715 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.00036191940307617 seconds
HomeMenu