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


gettimeofday() function in php

2158

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.

gettimeofday(float_value)

# 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


<?php
// Get the array from gettimeofday()
print_r(gettimeofday());
?>

Result:



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

Result:



Also you can format the output after returning the time.

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

Result:


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.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments