gettimeofday() | Get Current Time in PHP | Date Time Function

gettimeofday() function in php

0 785

If you want to get the current time of the day, then here is an inbuilt function i.e. gettimeofday(). This function gives time in seconds.

Let's have a look on the function:-

gettimeofday() function gives an associative array. This function contains one parameter which is optional.


# float_value: If this parameter is set as true then the function returns a float value instead of an array.

In this associative array the returned values have their own meaning. These are:-

1. sec => Defines the seconds since the Unix Epoch

2. usec => Defines the microseconds

3. minuteswest => Defines the minutes west of Greenwich

4. dsttime => This defines the type of dst correction

// Get the array from gettimeofday()


//Not get only float value from gettimeofday()
$currenttime= gettimeofday(true);
echo $currenttime;


Also you can format the output after returning the time.

echo $currenttime['sec'].$currenttime['usec'];


I hope this getcurrenttime function blog helped you. If you have faced any technical issue, you can feel free to contact with us and also if I have missed any important thing, you can comment below.

Share this blog with your friends and comment  below how do you like my blog.


Leave a Reply

    Waiting for your comments