PHP gettimeofday() function with example

PHP gettimeofday() function with example

PHP gettimeofday() function: Here, we will find out about the PHP gettimeofday() function with its syntax, parameters, returns type, and example.

PHP gettimeofday() function

gettimeofday() function is utilized to get the present time.

Syntax:

gettimeofday(return_float); 

Parameter(s):

return_float – It is a discretionary parameter which is utilized to indicate the arrival value as buoy rather than a cooperative cluster. To indicate the buoy value – we set its value as “genuine”.

Return value:

It restores an affiliated exhibit with the accompanying key values,

  • sec – it is utilized to get the time in seconds since the UNIX age
  • usec – it is utilized to get the time in microseconds
  • minuteswest – it is utilized to get the time in minutes (west of Greenwich)
  • dsttime – it is utilized for the kind of DST remedy

Example: PHP code to exhibit an example of gettimeofday() function

<?php
//getting the time with all keys
$result = gettimeofday();
echo "gettimeofday()...\n";
print_r($result);

//extracting indivisual values based on the keys
echo "sec:          $result[sec]\n";
echo "usec:         $result[usec]\n";
echo "minuteswest:  $result[minuteswest]\n";
echo "dsttime:      $result[dsttime]\n";

//getting time in float
$result = gettimeofday(true);
echo "result in float: $result\n";
?>

Output:

gettimeofday()...
Array
(
    [sec] => 1565701750
    [usec] => 950047
    [minuteswest] => 0
    [dsttime] => 0
)
sec:          1565701750
usec:         950047
minuteswest:  0
dsttime:      0
result in float: 1565701751.0216

Reference: PHP gettimeofday() function

Recent Posts

error: Alert: Content is protected!!