Backend Development 2 min read

PHP gettimeofday() Function: Usage, Parameters, Return Values, and Example

The PHP gettimeofday() function provides access to the system's current time, returning either an associative array with seconds, microseconds, timezone offset, and DST information or a floating‑point timestamp when the optional return_float parameter is set to true.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP gettimeofday() Function: Usage, Parameters, Return Values, and Example

The gettimeofday() function in PHP provides access to the system's gettimeofday(2) call, returning either an associative array with time components or a float when the optional $return_float parameter is set to true .

When called without arguments, it returns an array containing the keys "sec" (seconds since the Unix epoch), "usec" (microseconds), "minuteswest" (minutes west of Greenwich), and "dsttime" (daylight‑saving time type).

If $return_float is true , the function returns a single floating‑point number representing the current Unix timestamp with microsecond precision.

Example usage:

Typical output of the array form looks like:

Array (
    [sec] => 1073504408
    [usec] => 238215
    [minuteswest] => 0
    [dsttime] => 1
)
1073504408.23910
backendPHPfunctiontimegettimeofday
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.