English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP microtime() Function Usage and Examples

PHP Date & Time Function Manual

The microtime() function returns the current Unix timestamp and microseconds.

Definition and Usage

microtime()The function returns the current Unix timestamp and microseconds. By default, this function returns a string value containing microseconds and seconds separated by a space (milliseconds).

Syntax

microtime($get_as_float)

Parameter

Serial NumberParameters and Description
1

get_as_float(optional)

This is a boolean value that specifies whether the result should be a floating-point value. If the boolean valuetrueIf a parameter is passed, this function returns the result as a floating-point value.

Return value

The microtime() function returns the current Unix timestamp. By default, it returns a string value in milliseconds. If the boolean value true is passed as a parameter to this method, it returns the current time since the Unix epoch to the nearest microsecond, in seconds.

PHP version

This function was originally introduced in PHP version4introduced and can be used in all higher versions.

Online Example

The following examples demonstratemicrotime()Usage of the function-

<?php
   $time = microtime();
   print($time);
?>
Test to see‹/›

Output Result

0.60664200 1589305212

Online Example

Let's try to convertget_as_floatValue set totrue-

<?php
   $time = gettimeofday(true);    
   print_r($time); 
?>
Test to see‹/›

Output Result

1589298812.5101

Online Example

<?php
   $time_start = microtime(true);
   usleep(100);
   
   $time_end = microtime(true);
   $time = $time_end - $time_start;
   
   echo "In".$time."seconds, no operation was performed\n";
?>
Test to see‹/›

This produces the following results-

At 0.0018141269683838Within a second, no operation was performed