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.
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.23910Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
