gettimeofday()

gettimeofday() — Get current time.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

This is an interface to gettimeofday(2). It returns an associative array containing the data returned from the system call.

Signature

gettimeofday(bool $as_float = false): array|float

Parameters

ParameterTypeWhat it takes
$as_floatboolWhen set to true, a float instead of an array is returned.

Return value

By default an array is returned. If as_float is set, then a float is returned. Array keys: "sec" - seconds since the Unix Epoch "usec" - microseconds "minuteswest" - minutes west of Greenwich "dsttime" - type of dst correction "sec" - seconds since the Unix Epoch "usec" - microseconds "minuteswest" - minutes west of Greenwich "dsttime" - type of dst correction

Example

A runnable snippet:

print_r(gettimeofday()); echo gettimeofday(true);

Output:

Array ( [sec] => 1073504408 [usec] => 238215 [minuteswest] => 0 [dsttime] => 1 ) 1073504408.23910

All PHP 8.5 built-in functions

Reference card built from the PHP manual page gettimeofday() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.