PHP | gettimeofday() Function
The gettimeofday() function is an inbuilt function in PHP which is used to return the current time. It is an interface to Unix system call gettimeofday(2). It returns an associative array containing the data returned from the system call. The float option is sent as a parameter to the gettimeofday() function and returns an associative array containing the current time.
Syntax:
gettimeofday( $return_float )
Parameters: This function accepts single parameter $return_float which is optional. This parameter is used to set to TRUE, then it returns a float value instead of an array.
Return Value: It returns an associative array containing the current time. If $return_float parameter is set then it return float value.
The associative array consists of the following array keys:
- sec: It is used to specify the seconds since the Unix Epoch.
- usec: It is used to specify the microseconds.
- minuteswest: It is used to specify the minutes west of Greenwich.
- dsttime: It is used to specify the type of dst correction.
Exception: The $return_float parameter was added since PHP 5.1.0 version.
Below programs illustrate the gettimeofday() function in PHP:
Program 1:
<?php // Displaying the current time // as an associative array echo ("Current time is: "); print_r(gettimeofday()); ?> |
Current time is: Array
(
[sec] => 1536040360
[usec] => 178383
[minuteswest] => 0
[dsttime] => 0
)
Program 2:
<?php // Displaying the current time // as a float value echo ("Current time is: "); print_r(gettimeofday(true)); ?> |
Current time is: 1536040361.1613
Related Articles:
Reference: http://php.net/manual/en/function.gettimeofday.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | Ds\Map xor() Function
- D3.js | d3.max() function
- PHP | exp() Function
- PHP | each() Function
- PHP | Ds\Map put() Function
- PHP | pow( ) Function
- PHP | Ds\Set xor() Function
- PHP | key() Function
- CSS | rgb() Function
- PHP | min( ) Function
- PHP | pos() Function
- PHP | end() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



