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:

<?php
print_r(gettimeofday());
echo gettimeofday(true);
?>

Typical output of the array form looks like:

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

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPtimegettimeofday
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

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.