PHP | microtime() Function

The microtime() function is an inbuilt function in PHP which is used to return the current Unix timestamp with microseconds. The $get_as_float is sent as a parameter to the microtime() function and it returns the string microsec sec by default.

Syntax:

microtime( $get_as_float )

Parameters: This function accepts single parameter $get_as_float which is optional. If $get_as_float is set to TRUE then it specify that the function should return a float, instead of a string.



Return Value: It returns the string microsec sec by default, where sec is the number of seconds since the Unix Epoch (0:00:00 January 1, 1970, GMT), and microsec is the microseconds part. If the $get_as_float parameter is set to TRUE, it returns a float representing the current time in seconds since the Unix epoch accurate to the nearest microsecond.

Exceptions: The microtime() function is only available on operating systems that support the gettimeofday() system call.

Below programs illustrate the microtime() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Displaying the micro time as a string
echo ("The micro time is :");
echo(microtime());
?>

chevron_right


Output:

The micro time is :0.51423700 1535452933

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Displaying the micro time as a float type
echo ("The micro time is :");
echo(microtime(true));
?>

chevron_right


Output:

The micro time is :1535452935.2589

Related Articles:

Reference: http://php.net/manual/en/function.microtime.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.