Home >>PHP Date Time Functions >PHP gettimeofday() Function

PHP gettimeofday() Function

PHP gettimeofday() Function

PHP gettimeofday() function is used to return the current time. It returns an associative array containing the data returned from the system call, that is the current time. It accepts only a single parameter $return_float which is optional. It returns an associative array containing the current time and return float value if $return_float parameter is set.

Syntax:

gettimeofday(return_float);

Parameter Values

Parameter Description
return_float This is an optional parameter. If it is set to TRUE, a float instead of an array is returned.

Here is an example of getdateofday() function in PHP:

<html>
<body>
<pre>
<?php
print_r(gettimeofday());
?>
</pre>
</body>
</html>
Output:
Array
(
    [sec] => 1580546770
    [usec] => 564597
    [minuteswest] => 0
    [dsttime] => 0
)

Example 2:

<html>
<body>
<?php
echo gettimeofday(true);
?>
</body>
</html>
Output:
1580546834.1366

No Sidebar ads