HomeMenu
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.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