English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Date & Time Function Manual
The gettimeofday() function gets the current time
gettimeofday()This function returns the current time of the day. By default, this function returns the current time in array form. If the boolean valuetrueIf passed as a parameter, this function returns the time as a floating-point number.
gettimeofday($return_float)
Number | Parameters and Description |
---|---|
1 | return_float($Optional) This is a boolean value that specifies whether the time should be a floating-point value. If the value is true, then this function returns the time as a floating-point value. The keys in the array are:
|
PHP gettimeofday()This function returns the current time. By default, this value will be an array containing the following keys: sec, usec, minuteswest, dsttime. If thereturn_floatIf the value is set to true, the time will be returned as a floating-point value.
This function was originally introduced in PHP version4introduced and can be used in all higher versions.
The following example demonstratesgettimeofday()Function Usage-
<?php $time = gettimeofday(); print_r($time); ?>Test and see‹/›
Output Result
Array ( [sec] => 1589298247 [usec] => 881165 [minuteswest] => 0 [dsttime] => 0 )
The following example prints the current time as a floating-point number-
<?php $time = gettimeofday(true); print_r($time); ?>Test and see‹/›
Output Result
1589298812.5101
You can extract individual time values as follows-
<?php $time = gettimeofday(); echo "sec: $time[sec]\n"; echo "usec: $time[usec]\n"; echo "minuteswest: $time[minuteswest]\n"; echo "dsttime: $time[dsttime]"; ?>Test and see‹/›
Output Result
sec: 1589301022 usec: 843115 minuteswest: 0 dsttime: 0
<?php print_r(gettimeofday()); echo gettimeofday(true); ?>Test and see‹/›
This produces the following results-
Array ( [sec] => 1589261767 [usec] => 31653 [minuteswest] => 0 [dsttime] => 0 ) 1589261767.032