PHP gettimeofday() Function

Example

Return the current time:

<?php
// Output the array returned by gettimeofday()
print_r(gettimeofday());
// Output the floating-point number returned by gettimeofday()
echo gettimeofday(true);
?>

Running Instance

Definition and Usage

The gettimeofday() function returns the current time.

Syntax

gettimeofday(return_float);
Parameters Description
return_float Optional. When set to TRUE, it returns a floating-point number instead of an array. The default is FALSE.

Technical Details

Return Value:

By default, it returns an associative array with the following array keys:

  • [sec] - Seconds since Unix Epoch
  • [usec] - Microseconds
  • [minuteswest] - Minutes West of Greenwich
  • [dsttime] - Summer Time Correction Type

If return_float If the parameter is set to true, it returns a floating-point number.

PHP Version: 4+
Update Log: PHP 5.1.0: Added return_float Parameters.