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