PHP Function Reference

PHP gettimeofday() Function



The PHP gettimeofday() function returns current time. It returns an associative array containing the data returned from the system call.

Syntax

gettimeofday(as_float)

Parameters

as_float Optional. When set to true, a float instead of an array is returned. Default is false.

Return Value

By default returns an array. If as_float is set, then a float is returned. Array keys are:

  • sec - seconds since the Unix Epoch
  • usec - microseconds
  • minuteswest - minutes west of Greenwich
  • dsttime - type of dst correction

Example: gettimeofday() example

The example below shows the usage of gettimeofday() function.

<?php
//displaying the array from gettimeofday()
print_r(gettimeofday());

echo "\n";

//displaying the float from gettimeofday()
echo gettimeofday(true);
?>

The output of the above code will be:

Array
(
    [sec] => 1629533306
    [usec] => 470530
    [minuteswest] => 0
    [dsttime] => 0
)

1629533306.4729

❮ PHP Date and Time Reference