The gettimeofday() function returns the current time of the day. By default, this function returns the current time as an array. If you pass the boolean value true as an argument, this function returns the time as floating point number.
gettimeofday($return_float)
Sr.No | Parameter & Description |
---|---|
1 |
return_float($Optional) This is a boolean value which is used to specify whether the time should be a floating point value or not. If this value is true, this function returns time as floating point value. |
PHP gettimeofday() function returns the current time. By default this value will be an array with keys: sec, usec, minuteswest, dsttime. If you set the return_float value to true, the time will be returned as floating-point value.
This function was first introduced in PHP Version 4 and, works with all the later versions.
Following example demonstrates the usage of the gettimeofday() function −
<?php $time = gettimeofday(); print_r($time); ?>
This will produce following result −
Array ( [sec] => 1589298247 [usec] => 881165 [minuteswest] => 0 [dsttime] => 0 )
Following example prints the current time as floating point −
Live Demo<?php $time = gettimeofday(true); print_r($time); ?>
This will produce following result −
1589298812.5101
You can extract individual values of time as shown below −
<?php $time = gettimeofday(); echo "sec: $time[sec]\n"; echo "usec: $time[usec]\n"; echo "minuteswest: $time[minuteswest]\n"; echo "dsttime: $time[dsttime]"; ?>
This will produce following result −
sec: 1589301022 usec: 843115 minuteswest: 0 dsttime: 0
<?php print_r(gettimeofday()); echo gettimeofday(true); ?>
This produces the following result −
Array ( [sec] => 1589261767 [usec] => 31653 [minuteswest] => 0 [dsttime] => 0 ) 1589261767.032