gettimeofday() function in PHP


The gettimeofday() function returns an array that contains current time information.

Syntax

gettimeofday(return_float)

Parameters

  • return_float  − When set to TRUE, a float instead of an array is returned.

Return

The gettimeofday() function returns an associative array by default. The following are the returned array keys

  • [sec]  − seconds since the Unix Epoch

  • [usec]  − microseconds

  • [minuteswest]  − minutes west of Greenwich

  • [dsttime]  − type of dst correction

Example

The following is an example −

 Live Demo

<?php
   print_r(gettimeofday());
?>

Output

Array (
   [sec] => 1539234547
   [usec] => 322766
   [minuteswest] => 0
   [dsttime] => 0
)

Example

The following is an example −

 Live Demo

<?php
   echo gettimeofday(true);
?>

Output

1539172203.5542

Example

The following is an example

 Live Demo

<?php
   $res = gettimeofday(); echo "$res[sec].$res[usec]";
?>

Output

1539172298.346375

Updated on: 24-Dec-2019

22 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements