Home » PHP

PHP gettimeofday() function with example

PHP gettimeofday() function: Here, we are going to learn about the PHP gettimeofday() function with its syntax, parameters, returns type, and example.
Submitted by IncludeHelp, on August 13, 2019

PHP gettimeofday() function

gettimeofday() function is used to get the current time.

Syntax:

    gettimeofday(return_float);

Parameter(s):

  • return_float – It is an optional parameter which is used to specify the return value as float instead of an associative array. To specify the float value – we set its value as "true".

Return value:

It returns an associative array with the following key values,

  • sec            - it is used to get the time in seconds since the UNIX epoch
  • usec          - it is used to get the time in microseconds
  • minuteswest         - it is used to get the time in minutes (west of Greenwich)
  • dsttime     - it is used for the type of dst correction

Example: PHP code to demonstrate 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







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.